anon_swe
anon_swe

Reputation: 9345

Using comparator with poker hands: error with compare method

I'm trying to sort poker hands using a custom compare function. A poker hand is represented as a 5-element String array. I've written a class called HandComparator that has a method as follows for comparing hands:

//return 1 for a being better hand, return -1 for b being better hand, 0 for tie
public static int winner(String[] a, String[] b) {...}

Now I have an array of poker hands (so of type String[][]) and I want to sort them by making use of this winner function.

So I have something like this in main:

allButtonHands = Arrays.sort(allButtonHands, new HandComparator());

and within HandComparator I have my compare function:

public int compare(String[] a, String[] b) {
    return winner(a, b);
}

Unfortunately, Eclipse gives me the following error:

The method compare(String[], String[]) of type HandComparator must override or implement a supertype method.

What am I doing incorrectly here?

Thanks!

Upvotes: 0

Views: 202

Answers (1)

Francisco Hernandez
Francisco Hernandez

Reputation: 2468

I need to see your HandComparator class, but I guess that is declared

public class HandComparator implements Comparator {

Try to change to

public class HandComparator implements Comparator<String[]> {

If not, please, post your HandComparator class

Upvotes: 3

Related Questions