How can I resolve this method's generic type at runtime?
My method signature: static <T> T get(String key)
The method must remain static.
How can I resolve this method's generic type at runtime?
My method signature: static <T> T get(String key)
The method must remain static.
Like this: (Hibernate code)
public class XXXDao<T> {
private Class<T> entityClass;
private Class<T> getEntityClass() {
if (entityClass == null) {
entityClass = (Class<T>) ((ParameterizedType) getClass()
.getGenericSuperclass()).getActualTypeArguments()[0];
}
return entityClass;
}
...
}