java-Integer的自动装箱与拆箱

package com.day9.Wrapclass;

public class Demo4Integer {

  /**
  * A:案例演示
  * JDK5的新特性自动装箱和拆箱
  * Integer ii = 100;
  * ii += 200;
  * B:注意事项
  * 在使用时,Integer x = null;代码就会出现NullPointerException。
  * 建议先判断是否为null,然后再使用。

  */
  public static void main(String[] args) {
    Integer i1=100;//自动装箱,把基本数据类型转成对象
    int a=i1+100;//自动拆箱,把对象转成基本数据类型
    System.out.println(a);
  }

}

posted @ 2017-12-28 22:52  简简单单zjl  阅读(1031)  评论(0编辑  收藏  举报