为什么结果为false ,true
public class Demo {
public static void main(String[] args) {
Integer a=new Integer(3);
Integer b= 3;
int c = 3;
System.out.println(a==b);
System.out.println(a==c);
}
}
为什么结果为false ,true
public class Demo {
public static void main(String[] args) {
Integer a=new Integer(3);
Integer b= 3;
int c = 3;
System.out.println(a==b);
System.out.println(a==c);
}
}
Integer是对象你要判断是否相等应该调用Integer.equal()方法,直接==判断是判断这两个对象的存储地址是否指向的是同一个。对于对象new出来就会分配一个存储出来,每个对象都有一个存储地址指向这个位置