Community
Participate
Working Groups
Compile this test case with the Eclipse compiler: import java.lang.reflect.*; import java.beans.*; public class X { void foo() { for (Constructor constr : Object.class.getConstructors()) { constr.getAnnotation(ConstructorProperties.class).value(); } } } It doesn't compile. Using HEAD (0.937), we report: ---------- 1. WARNING in D:\tests_sources\X.java (at line 6) for (Constructor constr : Object.class.getConstructors()) { ^^^^^^^^^^^ Constructor is a raw type. References to generic type Constructor<T> should be parameterized ---------- 2. WARNING in D:\tests_sources\X.java (at line 7) constr.getAnnotation(ConstructorProperties.class).value(); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Type safety: The method getAnnotation(Class) belongs to the raw type Constructor. References to generic type Constructor<T> should be parameterized ---------- 3. ERROR in D:\tests_sources\X.java (at line 7) constr.getAnnotation(ConstructorProperties.class).value(); ^^^^^ The method value() is undefined for the type Annotation ---------- 3 problems (1 error, 2 warnings) If we change it for: import java.lang.reflect.*; import java.beans.*; public class X { void foo() { for (Constructor<?> constr : Object.class.getConstructors()) { constr.getAnnotation(ConstructorProperties.class).value(); } } } it compiles fine. Both javac (1.6.0_13 and 1.7_b44) compile it fine. Not even a raw type warning. It requires 1.6 libraries as java.beans.ConstructorProperties is defined only in 1.6 and above.
Also note that in source scenario (not using reflect constructor from lib), javac (build 1.7.0-ea-b44) also rejects the code: import java.lang.annotation.Annotation; public class X<U> { <T extends Annotation> T getAnnotation(Class<T> annotationClass) { return null; } void foo(X x) { x.getAnnotation(ConstructorProperties.class).value(); } } @interface ConstructorProperties { String value(); } X.java:4: warning: [rawtypes] found raw type: X missing type parameters for generic class X<U> void foo(X x) { ^ X.java:5: warning: [unchecked] unchecked call to <T>getAnnotation(java.lang.Class<T>) as a member of the raw type X x.getAnnotation(ConstructorProperties.class).value(); ^ X.java:5: cannot find symbol symbol : method value() location: interface java.lang.annotation.Annotation x.getAnnotation(ConstructorProperties.class).value(); ^ 1 error 2 warnings
dup of bug 167952 *** This bug has been marked as a duplicate of bug 167952 ***
Verified for 3.5M6 using I20090310-0100