Skip to content

Commit 4187aeb

Browse files
committed
[docs update]补充包装类型缓存范围是否可以修改
1 parent 7e3887a commit 4187aeb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,11 @@ public class Test {
513513
514514
Java 基本数据类型的包装类型的大部分都用到了缓存机制来提升性能。
515515
516-
`Byte`,`Short`,`Integer`,`Long` 这 4 种包装类默认创建了数值 **[-128127]** 的相应类型的缓存数据,`Character` 创建了数值在 **[0,127]** 范围的缓存数据,`Boolean` 直接返回 `True` or `False`。
516+
`Byte`,`Short`,`Integer`,`Long` 这 4 种包装类默认创建了数值 **[-128127]** 的相应类型的缓存数据,`Character` 创建了数值在 **[0,127]** 范围的缓存数据,`Boolean` 直接返回 `TRUE` or `FALSE`。
517+
518+
对于 `Integer`,可以通过 JVM 参数 `-XX:AutoBoxCacheMax=<size>` 修改缓存上限,但不能修改下限 -128。实际使用时,并不建议设置过大的值,避免浪费内存,甚至是 OOM
519+
520+
对于`Byte`,`Short`,`Long` ,`Character` 没有类似 `-XX:AutoBoxCacheMax` 参数可以修改,因此缓存范围是固定的,无法通过 JVM 参数调整。`Boolean` 则直接返回预定义的 `TRUE` 和 `FALSE` 实例,没有缓存范围的概念。
517521
518522
**Integer 缓存源码:**
519523

0 commit comments

Comments
 (0)