Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b4RzcCS5JCAgcxLz7T
24 lines
900 B
Java
24 lines
900 B
Java
import java.lang.annotation.ElementType;
|
|
import java.lang.annotation.Retention;
|
|
import java.lang.annotation.RetentionPolicy;
|
|
import java.lang.annotation.Target;
|
|
import java.util.Arrays;
|
|
|
|
/** Where does an annotation end up when its @Target omits RECORD_COMPONENT? */
|
|
public class RecordTarget {
|
|
|
|
@Target(ElementType.FIELD)
|
|
@Retention(RetentionPolicy.RUNTIME)
|
|
@interface FieldOnly { }
|
|
|
|
record Message(@FieldOnly String text) { }
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
System.out.println("compiled: @Target(FIELD) annotation on a record component");
|
|
System.out.println("on the record component: "
|
|
+ Arrays.toString(Message.class.getRecordComponents()[0].getAnnotations()));
|
|
System.out.println("on the private field: "
|
|
+ Arrays.toString(Message.class.getDeclaredField("text").getAnnotations()));
|
|
}
|
|
}
|