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())); } }