Comparator/Comparators API change proposal
henry.jen at oracle.com
Mon Jun 3 18:24:10 PDT 2013
On Jun 3, 2013, at 6:13 PM, Henry Jen <henry.jen at oracle.com> wrote:
> On Jun 3, 2013, at 5:07 PM, Michael Hixson <michael.hixson at gmail.com> wrote:
>> Hi Henry,
>> 1. Does this code throw an NPE? It's not clear from the docs.
>> int result = Comparators
>> .compare(null, null);
> It should return 0; otherwise, it's a bug.
BTW, this is really not a best practice, which is why we change it from Comparator.nullsFirst() to Comparators.nullsFirst(Comparator).
I expect the null-friendly wrapper to be the last-step operation on an existing Comparator. I even thought about throwing IllegalStateException.
We really don't want to encourage null-friendlyness. By having nulls-friendly wrapper to be last step make the code easier to read and not guessing if a comparator in-between is null-friendly or not.
More information about the lambda-libs-spec-observers