public class Equivalence {
public static void main(String[] args) {
Integer n1 = new Integer(47);
Integer n2 = new Integer(47);
System.out.println(n1 == n2);
System.out.println(n1 != n2);
}
}
參考答案:false
true
因为==比较的是2个对象是不是同一个
Integer n1 = new Integer(47);
Integer n2 =n1;
==是true
Integer n1 = new Integer(47);
Integer n2 = new Integer(47);
用 n1.equals(n2)是true