/*
* @(#) EqualSign2.java
*/
public class EqualSign2 {
public static void main(String[] args) {
Object obj1 = new Object();
Object obj2 = new Object();
System.out.println("obj1 " + (obj1 == obj2 ? "==" : "!=") + " obj2");
System.out.println("obj1 " + (obj1.equals(obj2) ? "" : "not ") + "equals to obj2");
System.out.println();
String str1 = "abc";
String str2 = "abc";
System.out.println("str1 " + (str1 == str2 ? "==" : "!=") + " str2");
System.out.println("str1 " + (str1.equals(str2) ? "" : "not ") + "equals to str2");
System.out.println();
String strObj3 = new String("def");
String strObj4 = new String("def");
System.out.println("strObj3 " + (strObj3 == strObj4 ? "==" : "!=") + " strObj4");
System.out.println("strObj3 " + (strObj3.equals(strObj4) ? "" : "not ") + "equals to strObj4");
System.out.println();
System.exit(0);
}
}
[RUN]
obj1 != obj2
obj1 not equals to obj2
str1 == str2
str1 equals to str2
strObj3 != strObj4
strObj3 equals to strObj4
Press any key to continue . . .
问题:obj1,obj2 str1,str2 strObj3,strObj4 是否 == 、equals 都是根据什么判别的?