有人可以解释为什么a和b都是相等的,x和y不是都相等但是它们具有相同的值。
Integer a = 40;`// integer a
Integer b =40; // integer b
Integer x = 400; // why x and y are not equal
Integer y = 400; // how is that possible
if (a==b){ //first condition
System.out.println("a=b"); //if true print
}else {
System.out.println("a!=b"); // if not true
}
if(x==y){ // second condition
System.out.println("x=y"); // if true print
}else{
System.out.println("x!y"); // if not true print
}
答案 0 :(得分:0)
将对象(或实际上不好的做法)与==进行比较是错误的,因为大多数对象都会覆盖compareTo()
,显然Intege
不是例外。< / p>