How can I achieve this?
public class GenericClass
{
public Type getMyType()
{
//How do I return the type of T?
}
}
I used follow approach:
public class A {
protected Class clazz;
public A() {
this.clazz = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
public Class getClazz() {
return clazz;
}
}
public class B extends A {
/* ... */
public void anything() {
// here I may use getClazz();
}
}