自動裝箱/拆箱


import org.junit.Test;spa


public class Demo {.net

@Test get

public void fun1(){it

Integer i  = 10; //自動裝箱:  Integer i = Integer.valueOf(10);class

//Integer i = Integer.valueOf(10);import

}bug

@Test im

public void fun2(){junit

int i = new Integer(10);//自動拆箱: int i = (new Integer(10)).intValue();new

//Integer i1 = new Integer(10);

//int i2 = i1.intValue();

}

@Test

public void fun3(){

Integer i1 = new Integer(100);

Integer i2 = new Integer(100);

System.out.println(i1 == i2);//false

Integer i3 = 100;

System.out.println(i1 == i3);//false

Integer i4 = 100;

System.out.println(i3==i4);//true

Integer i5 = 200;

Integer i6 = 200;

System.out.println(i5==i6);//false

}

}

相關文章
相關標籤/搜索