【发布时间】:2014-12-14 05:20:13
【问题描述】:
我发现了一个有趣的事实,但我不知道它是怎么发生的。
Integer x = 10;
Integer y = 10;
System.out.print(x==y); // true
Integer x = 128;
Integer y = 128;
System.out.print(x==y); // false
【问题讨论】:
-
这里需要使用
.equals()。见this question;==和.equals()的行为不同。