提问一个java的问题:是有关equals()和==的,问题如下
publicstaticvoidmain(String[]args){Integera=newInteger(1);Integerb=newInteger(1);intc...
public static void main(String[] args) {
Integer a=new Integer(1);
Integer b=new Integer(1);
int c=1;
Long d=new Long(1);
System.out.println(a.equals(b));
System.out.println(a.equals(c));
System.out.println(b.equals(c));
System.out.println(a.equals(d));
System.out.println("-----------------------");
System.out.println(a==b);
System.out.println(a==c);
System.out.println(b==c);
}
运行结果是
true
true
true
false
-----------------------
false
true
true
这就怪了,a==c为true,b==c为true,a==b怎么就为false了呢?还有为什么a.equals(d)为false呢? 展开
Integer a=new Integer(1);
Integer b=new Integer(1);
int c=1;
Long d=new Long(1);
System.out.println(a.equals(b));
System.out.println(a.equals(c));
System.out.println(b.equals(c));
System.out.println(a.equals(d));
System.out.println("-----------------------");
System.out.println(a==b);
System.out.println(a==c);
System.out.println(b==c);
}
运行结果是
true
true
true
false
-----------------------
false
true
true
这就怪了,a==c为true,b==c为true,a==b怎么就为false了呢?还有为什么a.equals(d)为false呢? 展开
23个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询