I have a generics class, Foo
. In a method of Foo
, I want to get the class instance of type T
, but I just can\'t call T.
I have an (ugly but effective) solution for this problem, which I used recently:
import java.lang.reflect.TypeVariable;
public static Class getGenericClass()
{
__ ins = new __();
TypeVariable>[] cls = ins.getClass().getTypeParameters();
return (Class)cls[0].getClass();
}
private final class __ // generic helper class which does only provide type information
{
private __()
{
}
}