本帖最后由 覃宏海 于 2012-9-14 12:58 编辑
class MyComparator implements Comparator<Student>{
public int compare(Student s1,Student s2){
int num = new Integer(s1.getAge()).compareTo(new Integer(s1.getAge()),new Integer (s2.getAge()));
//int num = compare(new Integer(s1.getAge()),new Integer (s2.getAge()));为什么不能用compare??
if(num==0)
return s1.getName().compareTo(s2.getName());
return num;
}
}
改用compare后编译时出现了下面的错误提示!
MapText.java:37: 无法将 MyComparator 中的 compare(Student,Student) 应用于 (java.
lang.Integer,java.lang.Integer)
int num = compare(new Integer(s1.getAge()),new Integer (s2.getAg
e()));
^ |