任何人都可以告诉我输出更改的原因。递增和递减更改对象值
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)而不是==。 – gcandal