首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

求解释:Integer的有关问题

2013-09-05 
求解释:Integer的问题public class MyClass { public Integer startingI public void methodA() {Integer

求解释: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

热点排行