How can I achieve this?
public class GenericClass
{
public Type getMyType()
{
//How do I return the type of T?
}
}
As others mentioned, it's only possible via reflection in certain circumstances.
If you really need the type, this is the usual (type-safe) workaround pattern:
public class GenericClass {
private final Class type;
public GenericClass(Class type) {
this.type = type;
}
public Class getMyType() {
return this.type;
}
}