0
点赞
收藏
分享

微信扫一扫

自动装箱和拆箱

艾晓雪 2022-04-13 阅读 97
java
package com.study.exception.demo17;

public class IntegerDemo {
    //装箱:把基本数据类型转换为对应的包装类类型
    //拆箱:把包装类类型转换为对应的基本数据类型
    public static void main(String[] args) {
        Integer i = Integer.valueOf(100);
        //自动装箱
        Integer ii = 100;

//        ii = ii.intValue() + 200;
        //自动拆箱
        ii += 200;
        System.out.println(ii);

        Integer iii = null;
        if (iii != null){
            iii += 100;
            System.out.println(iii);
        }
    }
}
举报

相关推荐

0 条评论