Since Comparator<T>
is a functional interface, I can do this
Comparator<Instant> instantComparator = Instant::compareTo;
And I can now reverse it:
Comparator<Instant> instantComparatorReversed = instantComparator.reversed();
I can do this directly, however:
Comparator<Instant> cannotDoThis = (Instant::compareTo).reversed();
which makes sense since Instant::compareTo
after all is just a method, and in that context it will be just that. The only say to do it inline seems to be this:
Comparator<Instant> instantComparatorReversedWithCast = ((Comparator<Instant>)Instant::compareTo).reversed();
There is also
Comparator.<Instant>reverseOrder()
and as mentioned in comments
Comparator.<Instant>naturalOrder().reversed()
The question now is: is there a shorter/prettier way to do it "inline" than that?