Skip to content- public class Person<T> {
-
- }
-
- import java.lang.reflect.ParameterizedType;
- import java.lang.reflect.Type;
-
- public class Student extends Person<Student> {
- public static void main(String[] args) {
- Student st=new Student();
- Class clazz=st.getClass();
-
- System.out.println(clazz.getSuperclass());
-
-
- Type type=clazz.getGenericSuperclass();
- System.out.println(type);
-
- ParameterizedType p=(ParameterizedType)type;
-
- Class c=(Class) p.getActualTypeArguments()[0];
- System.out.println(c);
- }
- }
-
- 打印结果:
-
- class com.test.Person
- com.test.Person<com.test.Student>
- class com.test.Student