如何将 java.lang.reflect.Type
转换为 Class<T> clazz
?
如果我有下一个方法,它的参数为 Class<T>
:
public void oneMethod(Class<T> clazz) {
//Impl
}
Then another method which has an argument of java.lang.reflect.Type
and it calls oneMethod(Class<T> clazz)
and for it I need to convert java.lang.reflect.Type type
to Class<T>
:
public void someMehtod(java.lang.reflect.Type type) {
// I want to pass type arg to other method converted in Class<T>
otherMethod(¿How to convert java.lang.reflect.Type to Class<T>?);
}
可能吗?
原文由 Pau 发布,翻译遵循 CC BY-SA 4.0 许可协议
您必须确保
type
是Class
的实例,然后对其进行转换。当然,您还必须处理它不是
Class
的情况。