public class Employee {
String name;
public Employee(String var){ this.name=var;}
}
public class Main {
public static void main(String[] args){
String s1=new String("joe");
String s2=new String("joe");
Employee e1=new Employee("joe");
Employee e2=new Employee("joe");
system.out.println("When comparing String obj:"+s1.equals(s2)); output:TRUE
system.out.println("When comparing Employee obj:+e1.equals(e2)): output:FALSE
我知道我們必須重寫Employee類,但是爲什麼它正在爲String類,我能不能找到等號甲骨文文檔爲String類重寫方法also.Please需要幫助!等於絃樂VS等於爲員工/天波超視距雷達類
https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#equals(java.lang.Object)? – zerkms
當你聲明單獨的對象時,它將不符合條件,如果你將第二個對象聲明爲Employee e2 = e1,它將返回false。那麼它將返回true – Vickyexpert