package com.software.paramstype;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
public class TestParams3 {
public static void main(String[] args) {
System.out.println(Person.class.getGenericSuperclass());
System.out.println("Student.class.getSuperclass()\t"
+ Student.class.getSuperclass());
System.out.println("Student.class.getGenericSuperclass()\t"
+ Student.class.getGenericSuperclass());
System.out.println("Test.class.getSuperclass()\t"
+ TestParams3.class.getSuperclass());
System.out.println("Test.class.getGenericSuperclass()\t"
+ TestParams3.class.getGenericSuperclass());
System.out.println("Object.class.getGenericSuperclass()\t"
+ Object.class.getGenericSuperclass());
System.out.println("Object.class.getSuperclass()\t"
+ Object.class.getSuperclass());
System.out.println("void.class.getSuperclass()\t"
+ void.class.getSuperclass());
System.out.println("void.class.getGenericSuperclass()\t"
+ void.class.getGenericSuperclass());
System.out.println("int[].class.getSuperclass()\t"
+ int[].class.getSuperclass());
System.out.println("int[].class.getGenericSuperclass()\t"
+ int[].class.getGenericSuperclass());
Type genType = Student.class.getGenericSuperclass();
Type type = ((ParameterizedType) genType).getActualTypeArguments()[0];
if (type instanceof ParameterizedType) {
System.out.println(((ParameterizedType) type).getActualTypeArguments()[0]);
System.out.println(((ParameterizedType) type).getRawType());
} else if (type instanceof Class) {
System.out.println("type===>class");
} else {
System.out.println("type===>else");
}
}
class Dog<T> {
}
class Student extends Person<Dog<TestParams3>> {
}
}
Student.class.getSuperclass() class com.software.paramstype.Person
Student.class.getGenericSuperclass() com.software.paramstype.Person<com.software.paramstype.TestParams3$Dog<com.software.paramstype.TestParams3>>
Test.class.getSuperclass() class java.lang.Object
Test.class.getGenericSuperclass() class java.lang.Object
Object.class.getGenericSuperclass() null
Object.class.getSuperclass() null
void.class.getSuperclass() null
void.class.getGenericSuperclass() null
int[].class.getSuperclass() class java.lang.Object
int[].class.getGenericSuperclass() class java.lang.Object
class com.software.paramstype.TestParams3
class com.software.paramstype.TestParams3$Dog
Process finished with exit code 0