覆写equals()方法的问题
看到别人写的,代码如下:
--------------------------------------------------------------------------------------------------
public boolean equals(Object obj) {
if (this == obj) { //此处是比较两对象的地址么?
return true;
}
if (!(obj instanceof Student)) {
return false;
}
Student stu = (Student) obj;
if (stu.name.equals(this.name) && stu.age == this.age) {
return true;
} else {
return false;
}
}