一般都是用匿名内部类搞定,TreeMap<Student,String> tm = new TreeMap<>(new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
int num = o1.getName().compareTo(o2.getName());
if(num==0) {
num = o1.getAge() - o2.getAge();
}
return num;
}
}); |