I have a class called Module, which often needs to be sorted by priority. I therefore make it implement the Comparator interface, thus :
public int compareTo (Module d) {
System.out.println("Comparing better");
if (priority > d.priority) return -1;
if (priority < d.priority) return 1;
return 0;
}
public int compareTo (Object d) {
System.out.println("Comparing boring");
return 0;
}
Unhappily, the prints indicate that it is the second, default method that is being called when I ask for sorting of an array of subclasses of Module. I didn’t have this problem before I created the subclasses, so I’m reasonably sure this is the cause.
I tried making a compareTo method for each subclass, but it is still the generic method that is called. Does anyone have a good solution?

