RFR: 8180352: Add Stream.toList() method

Tagir Valeev amaembo at gmail.com
Thu Nov 5 02:37:50 UTC 2020


Hello!

> The min() and max() methods are not null hostile.  If you pass a
> null-friendly comparator (such as returned by the `nullsFirst()` and
> `nullsLast()` comparator combinators), nulls are not a problem.

No, it is the problem, the same as with findFirst(). Try it:

Comparator<String> nullFriendly =
Comparator.nullsFirst(Comparator.naturalOrder());
List<String> data = Arrays.asList("hello", null, "world");
System.out.println(Collections.min(data, nullFriendly)); // null -- correct
System.out.println(data.stream().min(nullFriendly)); // NPE!

With best regards,
Tagir Valeev.


More information about the core-libs-dev mailing list