public void sortByLastName(){
Collections.sort(list, new Comparator<Person>() {
public int compare(Person p1, Person p2){
return p1.getLastName().compareTo(p2.getLastName());
}
} );
}
此处显示的代码是 contactList 数组的一部分,我在其中按姓氏对列表进行排序,我似乎无法编译它,而且我看不出有什么问题。
编辑:编译器上的错误是
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method sort(List<T>, Comparator<? super T>) in the type Collections is not applicable for the arguments (Person[], new Comparator<Person>(){})
at ContactList.sortByLastName(ContactList.java:34)
at Main.main(Main.java:18)