How is Java unable to interpret this code:
private <T> Class<T> getClass(T object) {
return object.getClass();
}
I'm trying to visualise this and when I substitute in for an exmaple
private Class<String> getClass(String s) {
return s.getClass();
}
I get the same sort of error: required type <String>
provided type <? extends String>
. I've seen code that gets around this error by doing:
@SuppressWarnings("unchecked")
Class<T> clazz = (Class<T>) object.getClass();
What does this mean? What am I not understanding about this generics problem?