我最好的代碼片段:Integer類對象
public class Test{
public static void main(String args[]){
Integer a = 100;
Integer b = 100;
Integer c = 5000;
Integer d = 5000;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
if(a == b)
System.out.println("a & b Both are Equal");
else
System.out.println("a & b are Not Equal");
if(c == d)
System.out.println("c & d Both are Equal");
else
System.out.println("c & d are Not Equal");
}
}
我沒有得到爲什麼輸出是這樣的嗎? 的Output
是:
a & b Both are equal
c & d are not equal
我使用jdk1.7
**當equals()爲真時,對象**只有「相等」。使用'=='表示**引用**是相同的。 –