A strange error in java generic.
- by ???
This is ok:
Class<? extends String> stringClass = "a".getClass();
But this gets error:
<T> void f(T obj) {
Class<? extends T> objClass = obj.getClass();
}
I know I can cast it like:
<T> void f(T obj) {
@SuppressWarnings("unchecked")
Class<? extends T> objClass = (Class<? extends T>) obj.getClass();
}
But why the previous error? Will the next release of Java 7 will support such usage?