Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8303784 no-@Target annotations should be applicable to type parameter declarations
  3. JDK-8309743

Release Note: Annotations with No `@Target` Annotation Should Be Applicable to Type Parameter Declarations

    XMLWordPrintable

Details

    • Sub-task
    • Resolution: Delivered
    • P4
    • 21
    • 21
    • tools

    Description

      Prior to JDK 21, the `javac` compiler was not allowing annotations with no `@Target` annotation to be applied to type parameter declarations.

      This is a bug in the `javac` compiler in versions prior to JDK21. [JLS 9.6.4.1](https://docs.oracle.com/javase/specs/jls/se21/html/jls-9.html#jls-9.6.4.1) specifies that annotations without an `@Target` annotation are applicable in 'all declaration contexts', which includes type parameter declarations.

      Starting from JDK21, the `javac` compiler will accept code like:

      ```
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;

      @Retention(RetentionPolicy.RUNTIME)
      @interface Anno {}

      class C<@Anno T> {}
      ```

      This change affects compilations targeting `-source`/`--release` 14 and higher.

      Attachments

        Activity

          People

            cushon Liam Miller-Cushon
            mtrudeau Michel Trudeau
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: