• java Class的 getSuperclass与getGenericSuperclass区别


    Class的getInterfaces与getGenericInterface区别 http://www.cnblogs.com/maokun/p/6773076.html

    一、getSuperclass   返回直接继承的父类(由于编译擦除,没有显示泛型参数)

     Class<? super T> getSuperclass() 
              返回表示此 Class 所表示的实体(类、接口、基本类型或 void)的超类的 Class

    返回表示此 Class 所表示的实体(类、接口、基本类型或 void)的超类的 Class

    如果此 Class 表示 Object 类、一个接口、一个基本类型或 void,则返回 null。

    如果此对象表示一个数组类,则返回表示该 Object 类的 Class 对象。 

    返回:
    此对象所表示的类的超类。

    二、getGenericSuperclass  返回直接继承的父类(包含泛型参数)

     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()	" 
    + Student.class.getSuperclass()); System.out.println("Student.class.getGenericSuperclass() "
    + Student.class.getGenericSuperclass()); System.out.println("Test.class.getSuperclass() "
    + Test.class.getSuperclass()); System.out.println("Test.class.getGenericSuperclass() "
    + Test.class.getGenericSuperclass()); System.out.println("Object.class.getGenericSuperclass() "
    + Object.class.getGenericSuperclass()); System.out.println("Object.class.getSuperclass() "
    + Object.class.getSuperclass()); System.out.println("void.class.getSuperclass() "
    + void.class.getSuperclass()); System.out.println("void.class.getGenericSuperclass() "
    + void.class.getGenericSuperclass()); System.out.println("int[].class.getSuperclass() "
    + int[].class.getSuperclass()); System.out.println("int[].class.getGenericSuperclass() "
    + 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
  • 相关阅读:
    window.parent ,window.top,window.self 详解及parent和opener的区别
    jQuery $.extend()用法总结
    JQuery中each()的使用方法说明
    jQuery.isPlainObject()的作用
    change和onchange、click和onclick的区别
    zabbix客户端一键安装脚本(主动模式监控)
    jumpserver在centos 7上的部署
    用阿里云的免费 SSL 证书让网站从 HTTP 换成 HTTPS
    GitLab的安装及使用教程
    一个客户端一键安装环境和服务的shell脚本
  • 原文地址:https://www.cnblogs.com/GarfieldEr007/p/9960391.html
Copyright © 2020-2023  润新知