File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change
1
+ 《《《 [ 返回首页] ( ../README.md ) <br />
2
+ 《《《 [ 上一节] ( 02_Reflected_Types_are_Reifiable_Types.md )
3
+
1
4
## 对原始类型的反思
2
5
3
6
` Java ` 中的每种类型(包括基元类型和数组类型)都具有类文字和相应的类标记。
4
7
5
- 例如,` int.class ` 表示整数的基本类型的类标记(该标记也是静态字段 ` Integer.TYPE ` 的值)。 这个类标记的类型不能是 ` Class<int> ` ,因为 ` int ` 不是一个引用类型,所以它被认为是 ` Class<Integer> ` 。 可以说,这是一个奇怪的选择,因为根据这种类型,您可能期望调用 ` int.class.cast(o) ` 和 ` int.class.newInstance() ` 返回 ` Integer ` 类型的值,但实际上这些调用会引发异常。 同样,你可能会期待这个调用:
8
+ 例如,` int.class ` 表示整数的基本类型的类标记(该标记也是静态字段 ` Integer.TYPE ` 的值)。 这个类标记的类型不能是 ` Class<int> ` ,因为 ` int ` 不是一个引
9
+ 用类型,所以它被认为是 ` Class<Integer> ` 。 可以说,这是一个奇怪的选择,因为根据这种类型,您可能期望调用 ` int.class.cast(o) ` 和
10
+ ` int.class.newInstance() ` 返回 ` Integer ` 类型的值,但实际上这些调用会引发异常。 同样,你可能会期待这个调用:
6
11
7
12
``` java
8
13
java.lang.reflect. Array . newInstance(int . class,size)
12
17
13
18
另一方面,` int[].class ` 表示具有基本类型 ` integer ` 的组件的数组的类标记,并且此类标记的类型为 ` Class<int[]> ` ,这是允许的,因为 ` int[] ` 是引用类型。
14
19
20
+ 《《《 [ 下一节] (04_A Generic_Reflection_Library.md) <br />
21
+ 《《《 [ 返回首页] ( ../README.md )
You can’t perform that action at this time.
0 commit comments