Why aren't Integers cached in Java?

前端 未结 15 1594
無奈伤痛
無奈伤痛 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条回答
  •  -上瘾入骨i
    2020-11-27 05:59

    For Integer objects use the a.equals(b) condition to compare.

    The compiler will not do the unboxing for you while you compare, unless you assign the value to a basic type.

提交回复
热议问题