Let’s say I have a Method:
public void method(LinkedList<Integer> intList);
I use reflection to obtain the java.lang.reflect.Method for this method, and I want to obtain the ParameterizedType, ie. LinkedList<Integer>.
Unfortunately, using Method.getParameterTypes() I can only seem to get the non-parameterized Class Class<LinkedList>.
However in my debugger if I look at the Method object I san see that there is a “signature” field that does appear to contain the generic information:
(Ljava/util/LinkedList<Ljava/lang/Integer;>;)V
So how can I obtain the LinkedList parameterized type from the Method object?
Use
Method.getGenericParameterTypes. Sample code:Output: