Android:R.id.class.getFields()的“类”是什么?

时间:2012-07-17 08:47:53

标签: android class field

我决定理解我复制和粘贴的内容,而不是盲目地复制和粘贴,而我却被R.id.class.getFields()困住了!我最初的猜测是它将是一个静态Class变量,但id类是否有这样的?

R = R.java

的R类

id =内部id类R.java

class = ??

getFields()= Class.getFields()

2 个答案:

答案 0 :(得分:4)

R.java是一个班级。来自Resources的自动生成的类。 R.id正在访问内部类。 public static final class idR.id.classgetFields将为您提供R.id的Class对象,public方法将返回类R.id内的所有reflection字段。看看{{1}}机制。

编辑:reflection

答案 1 :(得分:1)

Class Overview
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.

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).

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
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!)