1

I'm getting a compiler error for this line:

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

My customized Comparator is pretty basic; here's the signature and constructor:

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

}

Is there an error because I'm passing an argument into the Comparator? I need to pass an argument...

2
  • 2
    the constructor argument shouldn't matter. what's the error you're getting and what is the definition of the variable terms? Commented Apr 17, 2010 at 22:28
  • "I'm getting a compiler error" -- WHAT is the error? How can you say something like that and leave it out? Please help us help you. Commented Apr 18, 2010 at 7:10

3 Answers 3

2

There's no reason you can't pass an argument to that constructor. Your code is missing:

  1. The superclass. Your constructor calls super() so I assume there is one; and

  2. The compare() method required by the Comparator interface.

What exactly is numberOfDocs meant to do here?

Sign up to request clarification or add additional context in comments.

1 Comment

@cletus compare() is implemented, but it is too large to post in this comment. you're right, i don't need the super() call, but i'm still getting the same error without that line. numberOfDocs is used in the compare() method for a calculation @oedo the error is: cannot find symbol method sort (Java.util.ArrayList<java.Lang.String>, projectPackage.QuerySorter_TFmaxIDF)
1

Your Comparator needs to compare Strings because your ArrayList contains Strings.

public class QuerySorter_TFmaxIDF implements Comparator<Term> {  

has to be

public class QuerySorter_TFmaxIDF implements Comparator<String> {  

Comments

0

The problem lies with your comparator. It's for sorting Term-s but the array you're handing it via the Collections.sort() method has elements of type String.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.