How can I convert java.lang.reflect.Type
to Class
?
If I have one method as next which has an argument of Class
Andy Turner answer is correct, however if you need to retrieve a class from a type parameter this is a complete example:
private static class MyClass extends ArrayList {
}
public static void main(String[] args) {
ParameterizedType arrayListWithParamType
= (ParameterizedType) MyClass.class.getGenericSuperclass();
Type integerType = arrayListWithParamType.getActualTypeArguments()[0];
Class> integerClass = (Class>) integerType;
System.out.println(integerClass == Integer.class);
}