我知道我比较引用,而我使用==这不是一个好主意,但我不明白为什么会发生这种情况。为什么使用==两个整数的比较有时有效,有时不会?
Integer a=100;
Integer b=100;
Integer c=500;
Integer d=500;
System.out.println(a == b); //true
System.out.println(a.equals(b)); //true
System.out.println(c == d); //false
System.out.println(c.equals(d)); //true
是的它是重复的!我在这里得到了完美的答案http://stackoverflow.com/questions/10002037/comparing-integer-values-in-java-strange-behavior。谢谢你们。 – Hiru