我们如何实施比较方法,将Employee
s与其员工ID进行比较?
public int compare(Employee emp1, Employee emp2) {
throw new UnsupportedOperationException("Not supported yet.");
if(emp1.getEmpid()<emp2.getEmpid())
{
return -1;
}
else if(emp1.getEmpid()>emp2.getEmpid())
return 1;
else
return 0;
}
答案 0 :(得分:1)
public int compare(Employee emp1, Employee emp2) {
if(emp1==null || emp1==null ){
throw new UnsupportedOperationException("Not an Employee instance");
}
if(emp1.getEmpid()<emp2.getEmpid()){
return -1;
}
else if(emp1.getEmpid()>emp2.getEmpid()){
return 1;
}
return 0;
}
答案 1 :(得分:0)
从代码中删除throw new UnsupportedOperationException("Not supported yet.");
行。它由你的IDE添加(我认为),这里没有必要。