package WrapperTest;标签:面试题,包装,System,new,println,Integer,public,out From: https://www.cnblogs.com/liujy2233/p/16795995.html
import org.junit.Test;
/**
* @author liu$
* @version 1.0
* @description: TODO
* @date $ $
*/
public class wraptest {
public void test() {
Object o1 = true ? new Integer(1) : new Double(2.0);
System.out.println(o1); // 1.0 由于三元运算符要求类型统,Interger类型会自动提升为Double类型
}
public void test1() {
Integer i = new Integer(3);
Integer j = new Integer(3);
System.out.println(i == j); //false 此时创建了两个对象,地址值不相同
Integer m = 1;
Integer n = 1;
System.out.println(m == n); //true
//Intergercache()中有个Interger[]数组,只能存储-128到127,超过了则创建新数组相当于新建一个对象
Integer x = 128;
Integer y = 128;
System.out.println(x == y); //false
}
}