Possible Duplicate:
Get generic type of java.util.List
I have a Map and I want to get the type of T from an instance of that Map. How can I do that?
e.g. I want to do something like:
Map<String, Double> map = new HashMap<String, Double>();
...
String vtype = map.getValueType().getClass().getName(); //I want to get Double here
Of course there’s no such ‘getValueType()’ function in the API.
You can’t get it from the instance, because in Java generics the type parameter is available only at compile time, not at run time.
This is known as type erasure. A more formal definition is provided in the JLS.