Java 自动拆箱

  public static void main(String[] args) {
        UnBoxing();
    }

    public static Long getLong(){
        Long a=null;
        return a;
    }

    public static void UnBoxing(){
        // 自动拆箱,由于a为Null
    // 会调用Integer.intValue方法自动拆箱包装器类型为基本数据类型。
        long b=getLong();// 出现 NullPointerException
        System.out.println(b);
    }

 

posted @ 2015-09-18 14:47  er_bao  阅读(150)  评论(0编辑  收藏  举报