使用ParameterizedType获取泛型对象

publicclassDemo{privateClass clazz;publicTgetDemo()throwsInstantiationException, IllegalAccessException{returnclazz.newInstance(); }publicstaticvoidtest()throwsInstantiationException, IllegalAccessException{ String str =newDemo().getDemo(); } }



TypesuperClass = getClass().getGenericSuperclass();Typetype= ((ParameterizedType) superClass).getActualTypeArguments()[0];

你可能感兴趣的:(使用ParameterizedType获取泛型对象)