C
Cherukan
If I have a Class parameter, I can get the type of the parameter and
use it.
void method(Class<T> clazz)
{
Map<String, T> t = new HashMap<String, T>();
}
Is there any way to do the reverse, i.e. with a type variable, is there
a way
to get the Class ?
void <T> method(T t) {
Class<T> clazz = T.class; // does not work
Class<T> clazz = t.getClass(); // works, but only if t is not null
}
Thx
use it.
void method(Class<T> clazz)
{
Map<String, T> t = new HashMap<String, T>();
}
Is there any way to do the reverse, i.e. with a type variable, is there
a way
to get the Class ?
void <T> method(T t) {
Class<T> clazz = T.class; // does not work
Class<T> clazz = t.getClass(); // works, but only if t is not null
}
Thx