Community
Participate
Working Groups
The following piece of code compiles with JDK (with unchecked warning), but generates a compilation error in eclipse: public class EnumCastTest { public <T extends Enum<T>> void doWithEnumClass(Class<T> enumClass) { } public void f() { Class< ? > cl = null; // Returned by Class.forName("xyz"); doWithEnumClass((Class<Enum>) cl); } } Eclipse says, there is a bound mismatch when calling "doWithEnumClass" with the casted enum-class. ciao Volker
Reproduced in 3.1M6. We say: ---------- 1. ERROR in X.java (at line 7) doWithEnumClass((Class<Enum>) cl); ^^^^^^^^^^^^^^^ Bound mismatch: The generic method doWithEnumClass(Class<T>) of type X is not applicable for the arguments (Class<Enum>) since the type Enum is not a valid substitute for the bounded parameter <T extends Enum<T>> ---------- 2. WARNING in X.java (at line 7) doWithEnumClass((Class<Enum>) cl); ^^^^^^^^^^^^^^^^ Type safety: The cast from Class<?> to Class<Enum> is actually checking against the erased type Class ---------- 2 problems (1 error, 1 warning) Javac says: X.java:7: warning: [unchecked] unchecked cast found : java.lang.Class<capture of ?> required: java.lang.Class<java.lang.Enum> doWithEnumClass((Class<Enum>) cl); ^ X.java:7: warning: [unchecked] unchecked method invocation: <T>doWithEnumClass(java.lang.Class<T>) in X is applied to (java.lang.Class<java. lang.Enum>) doWithEnumClass((Class<Enum>) cl); ^ 2 warnings
Issue is related to fix for bug 86838. Added GenericTypeTest#test571-572.
*** This bug has been marked as a duplicate of 90879 ***