But that's more work (and more boilerplate) than simply passing an anonymous comparator to the sort function.
myArray.sort(new Comparator<MyClass> ({ @Override CompareTo(MyClass lhs, MyClass rhs) { return rhs.compare(lhs); } }));
In any case, there is a more elegant solution in Go, which is simply:
sort.Sort(sort.Reverse(array))
Nope. Clojure and Haskell. Clojure:
user=> (sort > (vals {:foo 5, :bar 2, :baz 10})) (10 5 2)
>>> sortBy (flip compare) . map snd $ [("foo", 5), ("bar", 2), ("baz", 10)] [10,5,2]
In any case, there is a more elegant solution in Go, which is simply:
You need to open your mind a little bit, to learn a new language.