码迷,mamicode.com
首页 > 移动开发 > 详细

Java 中包装类wrapped type之间以及和primitive type的比较

时间:2015-06-09 00:53:13      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

注意, 包装类的实例之间比较, 是不能直接用 == 的

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Integer a = new Integer(1);
        Integer b = new Integer(1);
        int c=1;
        Integer e = 1;
        System.out.println("a==b:"+(a==b));
        System.out.println("a==c:"+(a==c));
        System.out.println("a==e:"+(a==e));
        System.out.println("c==e:"+(c==e));
    }

结果:
a==b:false
a==c:true
a==e:false
c==e:true

Java 中包装类wrapped type之间以及和primitive type的比较

标签:

原文地址:http://www.cnblogs.com/milton/p/4562339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!