class Mycom implements Comparator<Teacher>{
public int compare(Teacher t1,Teacher t2){
int n1 = t1.name.compareTo(t2.name);
int n2 = (n1 == 0 ? t1.age - t2.age : n1);
int n3 = (n2 == 0 ? t1.sex - t2.sex : n2);
return n3;
}
}
说是这样不用自定义类去实现Comparable借口,但是自己还要创建一个类去实现compareTo接口,意义何在?
|
|