基本上,我创建了一个自定义链表类
public class LList<T> implements ListInterface<T>{
然而,当我尝试对自定义链表进行排序时,我收到错误,找不到合适的构造函数。 这是错误
no suitable method found for sort(ListInterface<Patient>)
method Collections.<T#1>sort(List<T#1>) is not applicable
(cannot infer type-variable(s) T#1
(argument mismatch; ListInterface<Patient> cannot be converted to List<T#1>))
method Collections.<T#2>sort(List<T#2>,Comparator<? super T#2>) is not applicable
(cannot infer type-variable(s) T#2
(actual and formal argument lists differ in length))
where T#1,T#2 are type-variables:
T#1 extends Comparable<? super T#1> declared in method <T#1>sort(List<T#1>)
T#2 extends Object declared in method <T#2>sort(List<T#2>,Comparator<? super T#2>)
这是我对患者名单进行排序的方式
ListInterface<Patient> patientList = new LList<>();
Collections.sort(patientList);
这是患者类中的orverride方法
@Override
public int compareTo(Patient t) {
int patientSeriouness = t.seriousness;
Date arrival = t.date;
if (this.seriousness == patientSeriouness) {
return this.date.compareTo(arrival);
} else {
return Integer.compare(this.seriousness, patientSeriouness);
}
}
我的问题究竟是什么?谢谢你的教学。