重写equals方法,怎么显示还是false
public boolean equals(Object obj){
if(this == obj){
return true;
}
if(obj == null){
return false;
}
if(!(obj instanceof Course))
return false;
Course course = (Course)obj;
if(this.name == null){
if(course.name == null)
return true;
else
return false;
}else{
if(this.name.equals(course.name))
return true;
else
return false;
}
}
下一个代码:
public void testListContains(){
Course course = couresToSelect.get(0);
System.out.println(couresToSelect.contains(course));
Course course2 = new Course(course.id,course.name);
System.out.println(couresToSelect.contains(course2));
}