使用ParameterizedType获取泛型对象
2019-03-24 本文已影响0人
愚公孙子
publicclassDemo{privateClass clazz;publicTgetDemo()throwsInstantiationException, IllegalAccessException{returnclazz.newInstance(); }publicstaticvoidtest()throwsInstantiationException, IllegalAccessException{ String str =newDemo().getDemo(); } }
TypesuperClass = getClass().getGenericSuperclass();Typetype= ((ParameterizedType) superClass).getActualTypeArguments()[0];