获取java泛型中的对象类型,可以参考如下代码:
/**
* 通过反射取到 List中 T 的类型
* @param clazz
* @param field
* @return
*/
public static Class extends Object> getGenericType(Class extends Object> clazz, Field field){
Method getMethod = getGetMethodByField(clazz,field);
ParameterizedType pt= (ParameterizedType)getMethod.getGenericReturnType();
Class extends Object> type = (Class>)pt.getActualTypeArguments()[0];
//System.out.println(type.getSimpleName());
//System.out.println(type.getPackage());
return type;
}