-
Sub-task
-
Resolution: Delivered
-
P4
-
21
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.
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.