public void testListContains(){
Course courses1=coursesToSelect.get(0);
System.out.println("课程信息为"+courses1.id+":"+courses1.name+","+coursesToSelect.contains(courses1));
Course courses2=new Course(courses1.id,courses1.name);
System.out.println("课程信息为"+courses2.id+":"+courses2.name+","+coursesToSelect.contains(courses2));
}
public boolean eaquals(Object obj){
if(this==obj)
return true;
if(obj==null)
return false;
if(!(obj instanceof Course))
return false;
//通过以上3个if判断,obj是一个Course类型且不为空的对象。
Course courses=(Course)obj;
if(this.name==null){
if(courses.name!=null)
return false;
else return true;
}
else
if(this.name.equals(courses.name))
return true;
else return false;
}