Convert java.lang.reflect.Type to Class clazz

前端 未结 6 1794
闹比i
闹比i 2021-02-12 11:43

How can I convert java.lang.reflect.Type to Class clazz?

If I have one method as next which has an argument of Class

6条回答
  •  生来不讨喜
    2021-02-12 12:00

    You have to ensure that type is an instance of Class, and then cast it.

    if (type instanceof Class) {
      Class clazz = (Class) type;
      otherMethod(clazz);
    }
    

    Of course, you also have to handle the case of it not being a Class.

提交回复
热议问题