Class类的getGenericSuperClass

    Returns the Type representing the direct superclass of the entity (class, interface, primitive type or void) represented by
    thisClass.

    If the superclass is a parameterized type, the Type object returned must accurately reflect the actual type parameters used
     in the source code. The parameterized type representing the 
    superclass is created if it had not been created before. See the
     declaration of ParameterizedType for the semantics of the 
    creation process for parameterized types. If thisClass represents either theObject class, an interface, a primitive type, or void, then null is returned. If this object represents an array class then theClass object representing theObject class is returned

    概括来说就是对于带有泛型的class,返回一个ParameterizedType对象,对于
    Object、接口和原始类型返回null,对于数 组class则是返回Object.class。
    ParameterizedType是表示带有泛型参数的类型的Java类型,JDK1.5引入了泛
    型之 后,Java中所有的Class都实现了Type接口,ParameterizedType则是继
    承了Type接口,所有包含泛型的Class类都会实现 这个接口。

    实际运用中还要考虑比较多的情况,比如获得泛型参数的个数避免数组越界等,具
    体可以参看Gson中的TypeToken类及ParameterizedTypeImpl类的代码。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值