请教有关equals()和hashCode()的问题
import java.lang.*;public class MyDate {
private int day;
private int month;
private int year;
public MyDate(int day, int month, int year) {
this.day = day;
this.month = month;
this.year = year;
}
public MyDate(int month,int year){
this.month =month;
this.year = year;
}
public MyDate(int year){
this.year = year;
}
public MyDate(MyDate date) {
this.day = date.day;
this.month = date.month;
this.year = date.year;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public MyDate addDays(int more_days) {
MyDate new_date = new MyDate(this);
new_date.day = new_date.day + more_days;
// Not Yet Implemented: wrap around code...
return new_date;
}
public void print() {
System.out.println("MyDate: " + day + "-" + month + "-" + year);
//取对象名称,没做到
//Class.forName(d.getClass());
//public final Class getClass()
//static Class forName(String className)
}
public boolean equals(MyDate day1){
if(day1.year==this.year&&day1.month==this.month&&day1.day==this.day)
return("ture");
else
return("false");
}
public int hashCode(){
}
}
equals()方法和hashCode()方法该怎么重写?
原版的equals()方法和hashCode()是如何?