Intellij idea给我报错:"Comparator中的compare(T,T)不能应用于(T,T)",代码如下:
public class LCCS<T extends Comparable<T>> {
private Comparator<T> comparator;
public LCCS(Comparator<T> comparator) {
this.comparator = comparator;
}
/**
* Loops the two given lists for finding the longest subequence
*
* @param list1 first list.
* @param list2 second list.
* @param <T> list item type.
* @return LCCS and the sublist indices of the subsequence in list1 and list2.
*/
private <T> Subsequence<T> getLongestSubsequence(List<T> list1, List<T> list2) {
Subsequence<T> output = null;
for (int indexList1 = 0; indexList1 < list1.size(); indexList1++)
for (int indexList2 = 0; indexList2 < list2.size(); indexList2++)
if (comparator.compare((T)list1.get(indexList1), (T)list2.get(indexList2)) //Here comes the error
output = inspectsubsequence(list1, list2, indexList1, indexList2, output);
return output;
}
}
我已经将参数类型更改为T,但仍显示相同的消息,只是捕获变成了T。非常感谢您的帮助。