【发布时间】:2013-07-05 19:10:30
【问题描述】:
谁能告诉我输出变化的原因。
public class Demo {
public void demo()
{
Integer y = 567;
Integer x = y;
System.out.println(x + " " + y);
System.out.println(y == x);
y++;
System.out.println(x + " " + y);
System.out.println(y == x);
y--;
System.out.println(x + " " + y);
System.out.println(y == x);
}
public static void main(String args[])
{
Demo obj = new Demo();
obj.demo();
}
}
输出:
567 567
true
567 568
false
567 567
False
这就是为什么我得到了最终的错误。
【问题讨论】:
-
试试 y.equals(x) 而不是 ==。