-
Bug
-
Resolution: Fixed
-
P5
-
5.0
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2152442 | OpenJDK6 | Jonathan Gibbons | P3 | Closed | Not an Issue |
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
- backported by
-
JDK-2152442 Declaration order of interdependent generic types should not matter
- Closed
- relates to
-
JDK-6804733 javac generates spourious diagnostics for ill-formed type-variable bounds
- Closed
-
JDK-6556683 Illegal type variable bound cause compiler crash
- Closed
-
JDK-8061427 Type variables should have lower/super bounds
- Closed
-
JDK-6569789 Compiler test lang/TYPE/type153/type15304/type15304.html fails since jdk7 b05
- Closed
-
JDK-6747877 Complex use of generics does not compile (javac and javadoc both crash)
- Closed
-
JDK-6193815 Restrictions on declaration of type variables
- Closed