0

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!

anon_swe
  • 8,791
  • 24
  • 85
  • 145
  • 1
    Well how is your `HandComparator` class defined? (And is there any reason you're using `String[]` to represent a hand of cards... I suspect you'll have a better time if you create a class for that, consisting of multiple `Card` references...) – Jon Skeet Nov 23 '15 at 17:02

1 Answers1

3

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

Francisco Hernandez
  • 2,378
  • 14
  • 18