mirror of
https://github.com/Snailclimb/JavaGuide
synced 2025-06-16 18:10:13 +08:00
[docs update]补充包装类型缓存范围是否可以修改
This commit is contained in:
parent
7e3887acb4
commit
4187aebf8b
@ -513,7 +513,11 @@ public class Test {
|
|||||||
|
|
||||||
Java 基本数据类型的包装类型的大部分都用到了缓存机制来提升性能。
|
Java 基本数据类型的包装类型的大部分都用到了缓存机制来提升性能。
|
||||||
|
|
||||||
`Byte`,`Short`,`Integer`,`Long` 这 4 种包装类默认创建了数值 **[-128,127]** 的相应类型的缓存数据,`Character` 创建了数值在 **[0,127]** 范围的缓存数据,`Boolean` 直接返回 `True` or `False`。
|
`Byte`,`Short`,`Integer`,`Long` 这 4 种包装类默认创建了数值 **[-128,127]** 的相应类型的缓存数据,`Character` 创建了数值在 **[0,127]** 范围的缓存数据,`Boolean` 直接返回 `TRUE` or `FALSE`。
|
||||||
|
|
||||||
|
对于 `Integer`,可以通过 JVM 参数 `-XX:AutoBoxCacheMax=<size>` 修改缓存上限,但不能修改下限 -128。实际使用时,并不建议设置过大的值,避免浪费内存,甚至是 OOM。
|
||||||
|
|
||||||
|
对于`Byte`,`Short`,`Long` ,`Character` 没有类似 `-XX:AutoBoxCacheMax` 参数可以修改,因此缓存范围是固定的,无法通过 JVM 参数调整。`Boolean` 则直接返回预定义的 `TRUE` 和 `FALSE` 实例,没有缓存范围的概念。
|
||||||
|
|
||||||
**Integer 缓存源码:**
|
**Integer 缓存源码:**
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user