Integer a=3;   =>    Integer a=Integer.valueOf(3);

  /**
*@description: 自动装箱和拆箱
*@auther: yangsj
*@created: 2019/4/2 15:48
*/
@Test
public void Test7(){
//自动装箱:
Integer num = 12;
//自动拆箱:
System.out.println(num + 12);//24
     //基本数据类型的对象缓存:
// -128~127 输出true
// 超过该范围,输出false
Integer num1 = 12;
Integer num2 = 12;
System.out.println(num1 == num2);//true Integer num3 = 129;
Integer num4 = 129;
System.out.println(num3 == num4);//false //手动装箱
Integer num5 = Integer.valueOf(12);
Integer num6 = Integer.valueOf(12);
System.out.println(num5 == num6);//true Integer num7 = Integer.valueOf(128);
Integer num8 = Integer.valueOf(128);
System.out.println(num7 == num8);//false Integer num9 = new Integer(12);
Integer num10 = new Integer(12);
System.out.println(num9 == num10);//false }
05-15 01:26