自动装箱/拆箱


import org.junit.Test;


public class Demo {

@Test

public void fun1(){

Integer i  = 10; //自动装箱:  Integer i = Integer.valueOf(10);

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

}

@Test

public void fun2(){

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

//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

}

}


你可能感兴趣的:(自动装箱/拆箱)