Community
Participate
Working Groups
Having an inner class in a generic class makes it "problematic" to use that class in deriving classes. A compile with "javac -Xlint:all *java" yields *no* warnings or errors. Below is the code that fully reproduces the problem. Included are also comments before lines that have errors or warnings (reported from the eclipse's compiler). SuperType.java: public class SuperType<T> { protected InnerType valueWrapper; protected class InnerType { private T value; protected InnerType(T value) { this.value = value; } } public SuperType(T value) { /* * This constructor exists only to show that the usage of the inner * class within its enclosing class makes no problems */ this.valueWrapper = new InnerType(value); } protected SuperType() { // Provided for the convenience of subclasses } } SubType.java: public class SubType<T> extends SuperType<T> { public SubType(T value) { /* The constructor SuperType <T>.InnerType(T) is undefined */ InnerType localValueWrapper = new InnerType(value); /* * Type mismatch: cannot convert from SuperType <T>.InnerType to * SuperType <T>.InnerType * * Type safety: The expression of raw type SuperType.InnerType is * converted to SuperType <T>.InnerType. References to generic type * SuperType <T>.InnerType should be parametrized. */ localValueWrapper = super.valueWrapper; } } Remarks: Making *everything* public in order to make sure that visibility is not somehow misinterpreted, yields no difference. In order to show that the problem is generics-specific, following can be done: * Introduce a type T (T.java: public class T {}) * Remove all generics-parameters (three occurences of <T>) from the above two files The compiler(s) (both javac and eclipse's compiler) work(s) perfectly in the latter scenario. The problem is rather annoying, as one must externally compile in order to be sure that there are no problems in the code. -- Irfy
The problem was discovered in Eclipse 3.1M4 under Windows XP with Sun's JDK5.0 (javac 1.5.0-rc). Not tested on any other configuration, but /should/ be Eclipse-specific, and presumably reproducible on other platforms with this Eclipse build. -- Irfy
Added GenericTypeTest#test492 *** This bug has been marked as a duplicate of 82349 ***