Class的getInterfaces与getGenericInterface区别 http://www.cnblogs.com/maokun/p/6773076.html
Class<? super T> |
getSuperclass() 返回表示此 Class 所表示的实体(类、接口、基本类型或 void)的超类的 Class。 |
返回表示此 Class 所表示的实体(类、接口、基本类型或 void)的超类的 Class。
如果此 Class 表示 Object 类、一个接口、一个基本类型或 void,则返回 null。
如果此对象表示一个数组类,则返回表示该 Object 类的 Class 对象。
Type |
getGenericSuperclass() 返回表示此 Class 所表示的实体(类、接口、基本类型或 void)的直接超类的 Type。 |
返回表示此 Class 所表示的实体(类、接口、基本类型或 void)的直接超类的 Type。
如果超类是参数化类型,则返回的 Type 对象必须准确反映源代码中所使用的实际类型参数。如果以前未曾创建表示超类的参数化类型,则创建这个类型。有关参数化类型创建过程的语义,请参阅 ParameterizedType 声明。
如果此 Class 表示 Object 类、接口、基本类型或 void,则返回 null。
如果此对象表示一个数组类,则返回表示 Object 类的 Class 对象。
GenericSignatureFormatError - 如果常规类签名不符合 Java Virtual Machine Specification, 3rd edition 规定的格式TypeNotPresentException - 如果常规超类引用不存在的类型声明MalformedParameterizedTypeException - 如果常规超类引用的参数化类型由于某种原因无法实例化代码实例:
package cn.test;
public class Test {
public static void main(String[] args) {
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"
+ Test.class.getSuperclass());
System.out.println("Test.class.getGenericSuperclass()\t"
+ Test.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());
}
}
class Person<T> {
}
class Student extends Person<Test> {
}
输出结果:
Student.class.getSuperclass() class cn.test.Person Student.class.getGenericSuperclass() cn.test.Person<cn.test.Test> 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
from: https://www.cnblogs.com/maokun/p/6773203.html
java Class的 getSuperclass与getGenericSuperclass区别
原文:https://www.cnblogs.com/GarfieldEr007/p/9960391.html