I have a class, which I have simplified to this:
final class Thing {
private final int value;
public Thing(int value) {
this.value = value;
}
public int getValue() {
return value;
}
@Override public String toString() {
return Integer.toString(value);
}
}
I want to sort an array of this thing. So I have created a simple copmarator:
private static final Comparator<Thing> reverse = new Comparator<Thing>() {
public int compare(Thing a, Thing b) {
return a.getValue() - b.getValue();
}
};
I then use the two argument form of Arrays.sort
.
This works fine for my test cases, but sometimes it goes all wrong with the array ending up in a strange but repeatable order. How can this be?