基本类型的装箱和拆箱

1-所有的基本类型,都有对应的类类型 
比如int对应的类是Integer 
这种类就叫做封装类

2-数字封装类有 
Byte,Short,Integer,Long,Float,Double 
这些类都是抽象类Number的子类

package digit;
public class TestNumber {
    public static void main(String[] args) {
        int i = 5;
        Integer it = new Integer(i);//基本类型转化为封装类型
        //Integer是Number的子类,所以打印true
        System.out.println(it instanceof Number);

//封装类型转换成基本类型

  int i2 = it.intValue();


    }
}

3-//自动转换就叫装箱

        Integer it2 = i;

通过=号实现

//自动转换就叫拆箱

        int i3 = it;

猜你喜欢

转载自blog.csdn.net/Whiteleaf3er/article/details/82020340