可能性の重複:
Integer wrapper objects share the same instances only within the value 127?一部のIntegerオブジェクトではなぜ== trueですか?
私はハーリドムガールSCJPから次のプログラムスニペットをコピーしてきたが、私は
には、出力を理解できないのです。
public class RQ200_60 {
public static void main(String[] args) {
Integer i = -10;
Integer j = -10;
System.out.print(i==j); // output: true -- why true?
System.out.print(i.equals(j)); // output: true
Integer n = 128;
Integer m = 128;
System.out.print(n==m); // output: false
System.out.print(n.equals(m)); // output: true
}
}
最初のprint文のための真の出力を与える上記のプログラムが、それは==関係演算子と参照比較であるため、それが偽与えることになって。しかし、3番目の印刷物は虚偽であり、私はこの矛盾を理解していません。
説明をいただければ幸いです。
http://stackoverflow.com/の範囲を超え質問/ 7309640/compare-two-integer、http://stackoverflow.com/questions/5581913/wrapper-class-and-operator、http://stackoverflow.com/questions/5117132/wrapper-objects-share-the-同じアドレス空間だけの値127、http://stackoverflow.com/questions/5865056/integer-construction-variations –