Summary: | [1.5][compiler] Wrong type inference leads to compile error | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Olivier Thomann <Olivier_Thomann> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | RESOLVED WORKSFORME | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | ||
Version: | 3.2 | ||
Target Milestone: | 3.2 M2 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Olivier Thomann
2005-08-11 10:00:03 EDT
javac compiles that code. But if you replace: final Class<Ann> AnnClass = Ann.class; with: final Class AnnClass = Ann.class; then javac reports the same error as we do. Interestingly, we accept the following: public class X { public static void main(String[] args) { try { X.class.getConstructor(new Class[0]).getAnnotation(Ann.class).message(); } catch(Exception e) { } } } @interface Ann { String message(); } Weird. Javac accepts the following code: import java.lang.reflect.Constructor; public class X { void bar(Constructor constructor, Class<Ann> ann) { constructor.getAnnotation(ann).message(); // OK } } @interface Ann { String message(); } but rejects: public class X { void bar(Constructor constructor, Class<Ann> ann) { constructor.getAnnotation(ann).message(); // KO - cannot find method #message() for Annotation } } class Constructor<V> { <T extends Annotation> T getAnnotation(Class<T> c) { return null; } } class Annotation {} class Ann extends Annotation { void message() {} } I am a bit puzzled by this difference in behavior, and am wondering if Annotation#getAnnotation(...) is meant to be treated in a special way (which no longer occurs in second example when defining source types) in a similar fashion as Object#getClass(...). Couldn't find any mention of this in the spec though. Suspicion is that this is a bug in javac, and the code should be rejected. Added GenericTypeTest#test800-802. Closing as javac bug. *** Bug 163560 has been marked as a duplicate of this bug. *** |