反射相关类Class说明

public final class Class<T>extends Objectimplements Serializable, AnnotatedElement, GenericDeclaration, Type
        
The in-memory representation of a Java class. This representation serves as the starting point for querying class-related information, a process usually called "reflection". There are basically three types of Class instances: those representing real classes and interfaces, those representing primitive types, and those representing array classes. 

        Java类加载器加载类SampleClass到内存中,会生成一个Class类型的对象mSampleClassInformationObject,这个对象保存了SampleClass类定义的相关信息,包括类名称,继承结构,方法,成员,注释等。如果需要知道这些信息,就可以通过Class对象mSampleClassInformationObject查询获得,这个过程称做“反射”。

        大体上有三种Class类型的实例,一种是表示类和接口的实例,二种是表示基本类型的实例,三种是表示数组类型的实例。

Class instances representing object types (classes or interfaces)
These represent an ordinary class or interface as found in the class hierarchy. The name associated with these Class instances is simply the fully qualified class name of the class or interface that it represents. In addition to this human-readable name, each class is also associated by a so-called signature, which is the letter "L", followed by the class name and a semicolon (";"). The signature is what the runtime system uses internally for identifying the class (for example in a DEX file). 
        表示对象类型(类和接口)的实例

        这种实例表示的是在类层次结构中出现的普通类和接口。这种类型的实例在创建时使用相关类和接口的完全限定(包含包路径)名称,除了这些可读的名称之外,每个类都与一个称为类签名的字符串相关联,这个字符串的的规则为:L+"完全限定名称" + ";",类签名是系统运行中识别类的标志。

Classes representing primitive types
These represent the standard Java primitive types and hence share their names (for example "int" for the int primitive type). Although it is not possible to create new instances based on these Class instances, they are still useful for providing reflection information, and as the component type of array classes. There is one Class instance for each primitive type, and their signatures are: 

B representing the byte primitive type 
S representing the short primitive type 
I representing the int primitive type 
J representing the long primitive type 
F representing the float primitive type 
D representing the double primitive type 
C representing the char primitive type 
Z representing the boolean primitive type 
V representing void function return values 
        表示基本数据类型的实例
        这种实例表示的是Java语言的基本类型,因此可以使用它们的名称(例如“int”表示整型)。虽然不能使用这种类型的Class实例来创建他所表示的基本类型的实例,它们依旧可以提供所表示的基本类型的信息,尤其是在基本类型对象作为数组元素的情况下。每个基本类型都对应一个Class实例,每个实例都对应一个类签名<基本类型,签名>:

        <byte,B>,<short,S>,<int,I>,<long,J>,<float,F>,<double,D>,<char,C>,<boolean,Z>,<void,V>

Classes representing array classes
These represent the classes of Java arrays. There is one such Class instance per combination of array leaf component type and arity (number of dimensions). In this case, the name associated with the Class consists of one or more left square brackets (one per dimension in the array) followed by the signature of the class representing the leaf component type, which can be either an object type or a primitive type. The signature of a Class representing an array type is the same as its name. Examples of array class signatures are: 

[I representing the int[] type 
[Ljava/lang/String; representing the String[] type 
[[[C representing the char[][][] type (three dimensions!) 
        表示数组类型的Class实例

        系统会为每一种不同的数组元素,不同的数组维度生成一个Class实例。

        [I      表示int[]

        [Ljava/lang/String        表示String[]

        [[[C        表示char[][][]


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值