Java 反射中的Type

本文介绍了 Java 中 Type 接口的基本概念及其使用方法。Type 是 Java 编程语言中所有类型的公共超接口,包括原始类型、参数化类型、数组类型、类型变量和原始类型。此外,还详细解释了 Class 类作为 Type 的子类的应用实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、java.lang.reflect.Type
  Type is the common superinterface for all types in the Java programming language. These include raw types, parameterized types,array types, type variables and primitive types.

public interface Type {
    /**
     * Returns a string describing this type, including information
     * about any type parameters.
     */
    default String getTypeName() {
        return toString();
    }
}

说明:Class类也是Type接口的子类,所以:

public void bind(Type type) {
    System.out.println(type.getTypeName());
}
bind(Test.class);  //测试调用

上面的测试会输出Test类的完整的名称(即包含包名)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值