Why are there any errors in the released Java source code?

I downloaded the JDK source code (6u23 build b5) for research, and Eclipsed decided to create it automatically. Surprisingly, he 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 of the new AWTAccessor.AWTEventAccessor () {} should implement the inherited abstract method AWTAccessor.AWTEventAccessor.getAccessControlContext (AWTEvent)

I thought this code should be absolutely correct, if not to be one of the best examples of using Java from which to learn. But it doesn't even compile!

Update: I exported the java package to a separate project, removed the default import of the java package to avoid possible namespace conflicts, and used JVM 1.6.0 to create it.

+4
source share
2 answers

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, but its IDE, which does not implement it, now compiles. (Unfortunately, Eclipse uses its own compiler and is not always exactly the same as the Sun / Oracle compiler)

I am sure that older versions of the compiler will result in an error for this line of code.

It used to be that if the type was not generic, all generics were disabled, even if that didn't make sense. In the case of this method.

 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) // constructor is not a generic type. private static String[] getAnnotationValue(Constructor constructor) { ConstructorProperties annotation = constructor.getAnnotation(ConstructorProperties.class); 

Older compilers suggest that this was not a general method, since the constructor is not general. However, the new compiler identifies this method on its own and it does not matter if the class is a typical type.

+2
source

Oh, there is a lot of confusion in the implementation of JLS in relation to the parameters of the universal method. It is possible that the code you posted is compiled using javac, but not with Eclipse (which, in my opinion, has an excellent but incorrect compiler). This compiles in Eclipse:

 private static String[] getAnnotationValue(Constructor<?> constructor) { ConstructorProperties annotation = constructor.getAnnotation(ConstructorProperties.class); 

This is not (your example with a constructor with a typed type):

 private static String[] getAnnotationValue(Constructor constructor) { ConstructorProperties annotation = constructor.getAnnotation(ConstructorProperties.class); 

Check this question with me recently. This gives me creeps:

Link ambiguous with generics

I would definitely look for an error in Eclipse

0
source

All Articles