How can I convert java.lang.reflect.Type
to Class
?
If I have one method as next which has an argument of Class
If you are willing to use a library, you could use com.google.guava:guava:12+
:
Class> clazz = com.google.common.reflect.TypeToken.of(type).getRawType();
Alternatively you could also use com.fasterxml.jackson.core:jackson-databind:2.8.x
:
Class> clazz = com.fasterxml.jackson.databind.type.TypeFactory.rawClass(type);
This handles all cases correctly and you will get the type-erased class of your type.