/**
*我的t.equals(te)為true
import java.util.Date;
import java.util.GregorianCalendar;
public class Test3 {
public static void main(String[] args) {
T3 t=new T3();///name="李楠"
Te3 te=new Te3();////name="劉洋"
System.out.println(t.equals(te));//true
System.out.println("==============================");
System.out.println(te.equals(t));///false
}
}
class T3{
public boolean equals(Object otherObject){
if(this==otherObject){
System.out.println("1");
return true;
}
if(otherObject==null){
System.out.println("2");
return false;
}
if(!(otherObject instanceof T3)){
System.out.println("4");
return false;
}
T3 other=(T3) otherObject;
return name.equals(other.name) && salary==other.salary && hireDay.equals(other.hireDay);
}
private String name="李楠";
private double salary=50000;
private Date hireDay=new GregorianCalendar(1992,3,3).getTime();
}
class Te3 extends T3{
public void s(){
System.out.println("j");
}
public boolean equals(Object otherObject){
if(!super.equals(otherObject)){
System.out.println("5");
return false;
}
if(otherObject instanceof Te3){
Te3 other=(Te3)otherObject;
return name.equals(other.name) && salary==other.salary && hireDay.equals(other.hireDay);
}
else {
return false;
}
}
private String name="劉洋";
private double salary=50000;
private Date hireDay=new GregorianCalendar(1992,3,3).getTime();
}
看看這篇文章吧,折騰了幾天。http://blog.csdn.net/u010569227/article/details/10322895