日期:2014-05-20  浏览次数:20618 次

求解释:Integer的问题
public class MyClass {
 public Integer startingI;
 public void methodA() {
  Integer i = new Integer(25);
  startingI = i;
  methodB(i);
 }
 private void methodB(Integer i2) {
  i2 = i2.intValue();
  System.out.println(i2 == startingI);
  System.out.println(i2.equals(startingI));
 }
 public static void main(String[] args) {
  new MyClass().methodA();
 }
}

A.false
false

B.true
true

C.true
false

D.false
true
请各位知道的朋友帮忙分析分析。
Integer

------解决方案--------------------
D.
i2 == startingI为false的关键原因在于i2 = i2.intValue();这句,自动装箱的过程会new新对象
所以他们不“==”但是他们equals