As you can see from the behavior of the following program, this should be prohibited.
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.*;
@Retention(RUNTIME)
@interface A {
A[] values() default { @A() };
}
@A()
class Main {
public static void main(String[] args) {
A a = Main.class.getAnnotation(A.class);
System.out.println(a);
}
}
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.*;
@Retention(RUNTIME)
@interface A {
A[] values() default { @A() };
}
@A()
class Main {
public static void main(String[] args) {
A a = Main.class.getAnnotation(A.class);
System.out.println(a);
}
}
- relates to
-
JDK-4906400 (JSR175) compiler allows self-containing annotation types
- Resolved
-
JDK-6264216 Allow certain cyclic type references in annotation types
- Closed