【发布时间】:2012-08-25 16:38:23
【问题描述】:
可能重复:
Integer wrapper objects share the same instances only within the value 127?
How != and == operators work on Integers in Java?
我尝试将两个整数与以下情况进行比较,得到了意想不到的结果
-
当我执行以下操作时,@@@ 被打印出来了。
class C { static Integer a = 127; static Integer b = 127; public static void main(String args[]){ if(a==b){ System.out.println("@@@"); } } } -
当我执行以下操作时,@@@ 没有打印出来。
class C { static Integer a = 145; static Integer b = 145; public static void main(String args[]){ if(a==b){ System.out.println("@@@"); } } }
谁能告诉我可能是什么原因。
【问题讨论】:
-
如果有人可以格式化它..我无法...
-
如果您有兴趣了解更多详情vanillajava.blogspot.co.uk/2012/01/…
-
嘿,这看起来不错的解释..会读它
标签: java