Bug 90430 - [1.5][compiler] Casted Enum-class is not of correct type in Eclipse
Summary: [1.5][compiler] Casted Enum-class is not of correct type in Eclipse
Status: RESOLVED DUPLICATE of bug 90879
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M7   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-06 07:30 EDT by Volker Renneberg CLA
Modified: 2005-04-15 09:06 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Renneberg CLA 2005-04-06 07:30:43 EDT
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
Comment 1 Philipe Mulet CLA 2005-04-06 07:37:46 EDT
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
Comment 2 Philipe Mulet CLA 2005-04-06 07:52:11 EDT
Issue is related to fix for bug 86838.
Added GenericTypeTest#test571-572.
Comment 3 Philipe Mulet CLA 2005-04-15 09:06:43 EDT

*** This bug has been marked as a duplicate of 90879 ***