@Data
public class MySuperClazz<K, V> {
private K data;
private V value;
}
@Data
public class MySubClazz extends MySuperClazz<Integer, String>{
}
public class GetTClazz {
public static void main(String[] args) {
MySubClazz mySubClazz = new MySubClazz();
mySubClazz.setData(123);
mySubClazz.setValue("9999");
Class<? extends MySubClazz> mySubClazzClass = mySubClazz.getClass();
Type genericSuperclass = mySubClazzClass.getGenericSuperclass();
ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
System.out.println(Arrays.asList(parameterizedType.getActualTypeArguments()));
}
}
输出结果:
[class java.lang.Integer, class java.lang.String]