Skip to content

Commit aef31f1

Browse files
committed
Update java-basic-questions-01.md
1 parent a71b7ce commit aef31f1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/java/basis/java-basic-questions-01.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,9 @@ class BasicTypeVar{
574574
}
575575
```
576576
577-
### 包装类型的常量池技术了解么
577+
### 包装类型的缓存机制了解么
578578
579-
Java 基本类型的包装类的大部分都实现了常量池技术
579+
Java 基本数据类型的包装类型的大部分都用到了缓存机制来提升性能
580580
581581
`Byte`,`Short`,`Integer`,`Long` 这 4 种包装类默认创建了数值 **[-128127]** 的相应类型的缓存数据,`Character` 创建了数值在 **[0,127]** 范围的缓存数据,`Boolean` 直接返回 `True` or `False`。
582582
@@ -629,7 +629,7 @@ public static Boolean valueOf(boolean b) {
629629
630630
如果超出对应范围仍然会去创建新的对象,缓存的范围区间的大小只是在性能和资源之间的权衡。
631631
632-
两种浮点数类型的包装类 `Float`,`Double` 并没有实现常量池技术
632+
两种浮点数类型的包装类 `Float`,`Double` 并没有实现缓存机制
633633
634634
```java
635635
Integer i1 = 33;
@@ -653,7 +653,7 @@ Integer i2 = new Integer(40);
653653
System.out.println(i1==i2);
654654
```
655655
656-
`Integer i1=40` 这一行代码会发生装箱,也就是说这行代码等价于 `Integer i1=Integer.valueOf(40)` 。因此,`i1` 直接使用的是常量池中的对象。而`Integer i2 = new Integer(40)` 会直接创建新的对象。
656+
`Integer i1=40` 这一行代码会发生装箱,也就是说这行代码等价于 `Integer i1=Integer.valueOf(40)` 。因此,`i1` 直接使用的是缓存中的对象。而`Integer i2 = new Integer(40)` 会直接创建新的对象。
657657
658658
因此,答案是 `false` 。你答对了吗?
659659

0 commit comments

Comments
 (0)