注解的类容不详细展开,我们现在只需要知道要表示一个类其也是最基本的元素。除了注解,对于Class Field Method Constructor我还可以用各种限定符进行修饰那么如前言所述的 PUBLIC PROTECTED PRIVATE这些访问权限控制符我们又如何去表示呢?除了这些访问权限的控制修饰符还有很多其他修饰符又怎么表示?说到修饰符,此处不再赘述又一个隆重登场即Modifier。 以下是所有的修饰符:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* The {@code int} value representing the {@code public}
* modifier.
*/
public static final int PUBLIC = 0x00000001;
/**
* The {@code int} value representing the {@code private}
* modifier.
*/
public static final int PRIVATE = 0x00000002;
/**
* The {@code int} value representing the {@code protected}
* modifier.
*/
public static final int PROTECTED = 0x00000004;
/**
* The {@code int} value representing the {@code static}
* modifier.
*/
public static final int STATIC = 0x00000008;
/**
* The {@code int} value representing the {@code final}
* modifier.
*/
public static final int FINAL = 0x00000010;
/**
* The {@code int} value representing the {@code synchronized}
* modifier.
*/
public static final int SYNCHRONIZED = 0x00000020;
/**
* The {@code int} value representing the {@code volatile}
* modifier.
*/
public static final int VOLATILE = 0x00000040;
/**
* The {@code int} value representing the {@code transient}
* modifier.
*/
public static final int TRANSIENT = 0x00000080;
/**
* The {@code int} value representing the {@code native}
* modifier.
*/
public static final int NATIVE = 0x00000100;
/**
* The {@code int} value representing the {@code interface}
* modifier.
*/
public static final int INTERFACE = 0x00000200;
/**
* The {@code int} value representing the {@code abstract}
* modifier.
*/
public static final int ABSTRACT = 0x00000400;
/**
* The {@code int} value representing the {@code strictfp}
* modifier.
*/
public static final int STRICT = 0x00000800;
// Bits not (yet) exposed in the public API either because they
// have different meanings for fields and methods and there is no
// way to distinguish between the two in this class, or because
// they are not Java programming language keywords
至此我们需要表示一个类我需要 Class Field Method Constructor Annotation Modifier这四个类,直接表示一个类的当然还是Class这个类。Field Method Constructor这些都是包含于Class类中的。一个类可以有0-N个Field、Method,但是必定会有一个Constructor。对于Class Field Method Constructor的修饰至少有一个修饰符,这些元素也是可以被注解标记的。注解对于这些元素的修饰是可以有,也可以不存在的。 至此我们已经可以完完整的表示一个类了,然而在JAVA的世界,类和对象是最主要的,类实例化产生对象。然而还存在一些元素是不可以被实例化的如Interface、Enum、Annotation、数组和各种基础数据类型它们又怎么表示?那么笔者注意瞄了一眼Class类的注释。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
* Instances of the class {@code Class} represent classes and
* interfaces in a running Java application. An enum is a kind of
* class and an annotation is a kind of interface. Every array also
* belongs to a class that is reflected as a {@code Class} object
* that is shared by all arrays with the same element type and number
* of dimensions. The primitive Java types ({@code boolean},
* {@code byte}, {@code char}, {@code short},
* {@code int}, {@code long}, {@code float}, and
* {@code double}), and the keyword {@code void} are also
* represented as {@code Class} objects.
*
* <p> {@code Class} has no public constructor. Instead {@code Class}
* objects are constructed automatically by the Java Virtual Machine as classes
* are loaded and by calls to the {@code defineClass} method in the class
* loader.
*For example, the type of {@code String.class} is {@code