KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The following Java method fails to compile: <T extends Number> void foo(T t) { Class<? extends T> klass = t.getClass(); } Error received is: Type mismatch: cannot convert from Class<capture#3-of ? extends Number> to Class<? extends T> Can someone explain why Class<? extends T> is invalid, but Class<? extends Number> is fine? Javadoc says: The actual result type is Class<? extends |X|> where |X| is the erasure of the static type of the expression on which getClass is called. For example, no cast is required in this code fragment: Number n = 0; Class<? extends Number> c = n.getClass();
Tags (comma-separated)
Save Edits
Cancel