How can I achieve this?
public class GenericClass
{
public Type getMyType()
{
//How do I return the type of T?
}
}
One simple solution for this cab be like below
public class GenericDemo{
private T type;
GenericDemo(T t)
{
this.type = t;
}
public String getType()
{
return this.type.getClass().getName();
}
public static void main(String[] args)
{
GenericDemo obj = new GenericDemo(5);
System.out.println("Type: "+ obj.getType());
}
}