基本类型可以使用运算符直接进行计算,但是引用类型不可以。

 

自动拆箱:对象自动直接转成基本数值

 

自动装箱:基本数值自动直接转成对象

 

自动装箱(byte常量池)细节的演示

 

当数值在byte范围之内时,进行自动装箱,不会新创建对象空间而是使用已有的空间。

public class Demo04 {
    public static void main(String[] args) {
        /*Integer in1=500;
        Integer in2=500;
        System.out.println(in1==in2);//false
        System.out.println(in1.equals(in2));//true
*/        
        //byte常量池    -128   -     127
        Integer in1=50;//Integer in1=new Integer(50);
        Integer in2=50;//Integein2=in1;
        System.out.println(in1==in2);//false
        System.out.println(in1.equals(in2));//true
    }
}