Why aren't Integers cached in Java?

前端 未结 15 1603
無奈伤痛
無奈伤痛 2020-11-27 05:27

I know there are similar posts on the topic, but they don\'t quite address my question. When you do:

Integer a = 10;
Integer b = 10;
System.out.println(\"a =         


        
15条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 06:03

    Please also note that the cache range was -128 to 127 in Java 1.5 but Java 1.6 onward it is the default range i.e. you can set upper value >= 127 by passing -XX:AutoBoxCacheMax=new_limit from command line

提交回复
热议问题