The output of current program is "Strange". But both the variables share the same reference. Why are the second and third comparisons not true?
Integer a;
Integer b;
a = new Integer(2);
b = a;
if(b == a) {
System.out.println("Strange");
}
a++;
if(b == a) {
System.out.println("Stranger");
}
a--;
if(b == a) {
System.out.println("Strangest");
}
Output: Strange
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…