Guava 22.0 introduced Comparators#emptiesFirst(Comparator<T>) and Comparators#emptiesLast(Comparator<T>). Since these methods are still in @Beta, can their signatures be updated to accept a Comparator<? super T>, just like #least and #greatest, as well as various methods defined in java.util.Comparators?
Rationale: as it stands my compiler complains when I write emptiesFirst(naturalOrder()):
The method
emptiesFirst(Comparator<T>)in the typeComparatorsis not applicable for the arguments (Comparator<Comparable<? super Comparable<? super T>>>).
The workaround is to provide an explicit type parameter to either emptiesFirst or naturalOrder, but if the signatures are updated as suggested above that won't be necessary.
I think we should do this.
We don't often use "loose" generics, but here there's more reason to, as you explain. I know that we already use them in Ordering: nullsFirst/nullsLast, reverse, lexicographical. And in fact we carried that over to Comparators when copying lexicographical there. And our original API Review doc for emptiesFirst/emptiesLast, back when we were considering adding it to Ordering itself, says "(Technically this would use <S extends T> as does nullsFirst(), but that's an insignificant detail.)" So it appears that we even intended to do this, unless something is different about the static methods than the instance methods. But the Comparators.lexicographical signature suggests we consider them to be the same. (Internal discussion on CL 122475150.)
I'm going to make sure it doesn't break anything internally. Assuming not, I'll make the change. Thanks for bringing this up.
And sure enough, most internal callers have to provide an explicit type parameter. Yuck.
Most helpful comment
And sure enough, most internal callers have to provide an explicit type parameter. Yuck.