File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -137,13 +137,22 @@ System.out.println(m == n); // true
137
137
138
138
基本类型对应的缓冲池如下:
139
139
140
- - boolean values true and false
141
- - all byte values
142
- - short values between -128 and 127
143
- - int values between -128 and 127
144
- - char in the range \u0000 to \u007F
140
+ | 基本类型| 包装类型| 包装类型缓冲池| 缓冲池内容|
141
+ | :-:| :-:| :-:| :-:|
142
+ | boolean| Boolean| 无| 无|
143
+ | byte| Byte| ByteCache| Byte类型数据,数值范围[ -128, 127] |
144
+ | char| Character| CharacterCache| Character类型数据,数值范围[ 0, 127] ,对应字符内容为整个ASCII码表|
145
+ | short| Short| ShortCache| Short类型数据,数值范围[ -128, 127] |
146
+ | int| Integer| IntegerCache| Integer类型数据,数值范围默认[ -128, 127] ,最大值可调|
147
+ | long| Long| LongCache| Long类型数据,数值范围[ -128, 127] |
148
+ | float| Float| 无| 无|
149
+ | double| Double| 无| 无|
145
150
146
- 在使用这些基本类型对应的包装类型时,就可以直接使用缓冲池中的对象。
151
+ 在使用这些基本类型对应的包装类型时,如果该数值范围在缓冲池范围内,就可以直接使用缓冲池中的对象。
152
+
153
+ ** Integer缓冲池的特殊性**
154
+
155
+ 在jdk1.8所有的数值类缓冲池中,Integer的缓冲池IntegerCache很特殊,这个缓冲池的下界是-128,上界默认是127,但是这个上界是可调的,在启动jvm的时候,通过` -XX:AutoBoxCacheMax=<size> ` 来指定这个缓冲池的大小,该选项在JVM初始化的时候会设定一个名为` java.lang.IntegerCache.high ` 系统属性,然后IntegerCache初始化的时候就会读取该系统属性来决定上界。
147
156
148
157
[ StackOverflow : Differences between new Integer(123), Integer.valueOf(123) and just 123
149
158
] ( https://stackoverflow.com/questions/9030817/differences-between-new-integer123-integer-valueof123-and-just-123 )
@@ -152,7 +161,7 @@ System.out.println(m == n); // true
152
161
153
162
## 概览
154
163
155
- String 被声明为 final,因此它不可被继承。
164
+ String 被声明为 final,因此它不可被继承。(注意,所有8种基本类型对应的包装类型全都是由 ` final ` 修饰的不可变类)
156
165
157
166
在 Java 8 中,String 内部使用 char 数组存储数据。
158
167
You can’t perform that action at this time.
0 commit comments