import junit.framework.Assert;
import org.junit.Test;
public class AutoBox {
//Integer和int的自动拆箱和自动装箱的数据范围是-128——127,也就是一个字节表示的范围内
//其实String str1 = "main strings";与拆箱和自动装箱有异曲同工之效
//要说明白这个,就得明白,JAVA的栈和堆,这里主要说栈,就String str1 = "main strings";而不是String str2 = new String("main string");
//因为前者会在栈中存放,在存放"main strings"之前,会在栈中查找,是否已经存在"main strings",如果存在,则str1也指向该地址,就多个对象共享同一内存值
//这跟装箱和拆箱的-128——127的栈数据共享是一致的,而str2是调用new的,存放与堆,每次调用都会重新new出一块内存,而不会共享同一块内存值。
@Test
public void testAutoBoxing() {
Integer inter = 100;
Integer inter2 = inter;
System.out.println(inter == inter2);
inter2++;
System.out.println(inter == inter2);
int sum = 10 + 10;
Assert.assertEquals(21, sum);
}
@Test
public void testAutoBoxing2() {
// System.out.println(inter == inter2);
Integer inter = 100;
Integer inter2 = inter;
System.out.println(inter == inter2);
inter2++;
System.out.println(inter == inter2);
System.out.println(inter == inter2);
System.out.println(inter == inter2);
System.out.println(inter == inter2);
System.out.println(inter == inter2);
int sum = 10 + 10;
Assert.assertEquals(21, sum);
// Color.BLACK;
}
}