您必须正确覆盖和类的
equals()方法。
Student``Instructor
覆盖等于时,也应覆盖
hashCode()。新学生(姓名,ID,GPA);
例如,如下所示:
public boolean equals(Object o) { if (!(o instanceof Student)) { return false; } Student other = (Student) o; return name.equals(other.name) && id.equals(other.id) && GPA == other.GPA;}public int hashCode() { return name.hashCode();}这样,您就有机会
ArrayList找出哪个对象与删除时作为参数传递的对象相对应。如果您不重写上述方法,它将使用中的默认实现
Object,该默认实现会比较删除新
Student对象时肯定不同的内存地址。
您可以在javadocs的中阅读有关2种方法的更多信息
Object。



