1

我收到此行的编译器错误:

Collections.sort(terms, new QuerySorter_TFmaxIDF(myInteger));

我的自定义比较器非常基础;这是签名和构造函数:

public class QuerySorter_TFmaxIDF implements Comparator<Term>{  
private int numberOfDocs;
QuerySorter_TFmaxIDF(int n){
    super();
    numberOfDocs = n;
}

}

是否因为我将参数传递给比较器而出现错误?我需要通过一个论点...

4

3 回答 3

2

没有理由不能将参数传递给该构造函数。您的代码丢失:

  1. 超类。你的构造函数调用super(),所以我假设有一个;和

  2. compare()接口所需的方法Comparator

究竟是什么numberOfDocs意思?

于 2010-04-17T22:29:10.860 回答
1

您的 Comparator 需要比较字符串,因为您的 ArrayList 包含字符串。

public class QuerySorter_TFmaxIDF implements Comparator<Term> {  

必须

public class QuerySorter_TFmaxIDF implements Comparator<String> {  
于 2010-04-17T23:41:28.837 回答
0

问题在于您的比较器。它用于对 Term-s 进行排序,但您通过 Collections.sort() 方法处理它的数组具有字符串类型的元素。

于 2010-04-17T23:44:33.817 回答