Getting class of return generic type possible?
I want to know the class of a generic return type of a method, something like th开发者_如何学编程is:
<T> T getEntry() { System.out.println(T.class) }
The problem is, this is not a generic class, this is just a generic method, so I can't extract the generic type from the class. What I want to achieve is knowing what concrete type the caller wants without requiring the class, like:
<T> T getEntry(Class<?> clazz);
Is that possible?
Well if Kylar is right I've to resort to:
<T> T getEntry(String name, Class<T> clazz)
I wanted to avoid the extra argument :(
精彩评论