This is not possible in Java due to erasure . Most people add a type token instead. Example:
public <T> void putList(String key, List<T> list, Class<T> listElementType) { }
There are certain situations in which reflection can be obtained in the type parameter, but this is for cases when you have previously set the type parameter. For example:
public class MyList extends List<String> { private List<String> myField; }
In both cases, reflection can determine that List is of type String, but reflection cannot determine it for your case. You will have to use a different approach, such as a type marker.
Brad cupit
source share