您的位置:首页 > 移动开发

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

2015-06-09 00:16 399 查看
注意, 包装类的实例之间比较, 是不能直接用 == 的

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: