I think you can't do that. Check out this class:
public class TestClass
{
private List list = new ArrayList();
/**
* @param args
* @throws NoSuchFieldException
* @throws SecurityException
*/
public static void main(String[] args)
{
try
{
new TestClass().getClass().getDeclaredField("list").getGenericType(); // this is the type parameter passed to List
}
catch (SecurityException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (NoSuchFieldException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
new TestClass(). insert(new ArrayList());
}
public void insert(List tList)
{
ParameterizedType paramType;
paramType = (ParameterizedType) tList.getClass().getGenericInterfaces()[0];
paramType.getActualTypeArguments()[0].getClass();
}
}
You can get the type parameters from a class or a field but it is not working for generic methods. Try using a non-generic method!
OR
another solution might be passing the actual Class
object to the method.