Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
FULL PRODUCT VERSION : java version "1.5.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64) Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows 2000 [Version 5.00.2195] A DESCRIPTION OF THE PROBLEM : Discussed in more detail in the generics forum (http://forum.java.sun.com/thread.jsp?forum=316&thread=566266), this bug relates to the unnecessary restriction of the declaration order of generic types in a class or method. Basically the following class declaration public class MyClass<E, D super E> causes the following compiler errors Error: line (1) > expected Error: line (4) '{' expected Rewritten in another form, the following declaration public class MyClass<E extends D, D> causes the following compiler error Error: line (1) illegal forward reference Section 6.3 of the Language Specification says that "type parameters can appear as parts of their own bounds, or as bounds of other type parameters declared in the same section." The current behaviour appears to contradict this. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Attempt to compile either of the two following classes: public class MyClass<E, D super E> {} public class MyClass<E extends D, D> {} EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - Successful compilation for either form of the class declaration. ACTUAL - Compilation failures for both forms of the class declaration. ERROR MESSAGES/STACK TRACES THAT OCCUR : Compilation of public class MyClass<E, D super E> {} yields the following errors Error: line (1) > expected Error: line (4) '{' expected Compilation of public class MyClass<E extends D, D> {} yields the following error Error: line (1) illegal forward reference REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- Either public class MyClass<E, D super E> {} or public class MyClass<E extends D, D> {} ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : Current workaround involves swapping the declaration order of the generic types. This can be undesirable, particularly in my case, as the class needs to extend an interface, thus public class MyClass<D super E, E> implements MyInterface<E, D> so we have the awkward situation of the the generic types being reversed for the interface and the corresponding class, thus MyInterface<Integer, Number> obj = new MyClass<Number, Integer>(); Note that there are situations for which there appears to be no such workaround, for example public class SomeClass<S extends T, T extends SomeInterface<S>> {} ###@###.### 2004-11-09 20:10:37 GMT
|