I downloaded JDK source code (6u23 build b5) for research, and Eclipsed decided to automatically build it. Astonishingly, it found errors.
A few examples.
java.beans.MetaData, line 1365:
ConstructorProperties annotation = constructor.getAnnotation(ConstructorProperties.class);Type mismatch: cannot convert from Annotation to ConstructorProperties
java.awt.AWTEvent, line 220:
AWTAccessor.setAWTEventAccessor(new AWTAccessor.AWTEventAccessor() {The type new AWTAccessor.AWTEventAccessor(){} must implement the inherited abstract method AWTAccessor.AWTEventAccessor.getAccessControlContext(AWTEvent)
I thought this code supposed to be absolutely correct, if not being one of the best examples of Java usage that one can learn from. But that doesn’t even compile!
Update: I exported java package into individual project, removed the java package default import to avoid possible namespace conflicts and used JVM 1.6.0 to build it.
The problem you have here is that the specification for generics has evolved over time. 😐 The latest version of Sun/Oracle Java compiles this code correctly, however its the IDE which doesn’t realise it now compiles. (Unfortunately Eclipse uses its own compiler and its not always exactly the same as the Sun/Oracle compiler)
I am pretty sure older versions of the compiler would produce an error for this line of code.
It used to be that if a type was not a generic, all generics were turned off, even if that didn’t make sense. In the case of this method.
The older compilers would assume this was a non-generic method as the Constructor is not generic. However the newer compiler identifies this method is self contained and it shouldn’t matter whether the class is a generic type of not.