我是靠谱客的博主 能干中心,这篇文章主要介绍基本类型的装箱和拆箱,现在分享给大家,希望可以做个参考。

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;

最后

以上就是能干中心最近收集整理的关于基本类型的装箱和拆箱的全部内容,更多相关基本类型内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部