List.of rejects null values
The immutable factory methods List.of, Set.of, and Map.of reject null elements or keys and values. Validate inputs or use a collection implementation whose null policy matches the API contract.
Stream.toList()allows null elements, whileCollectors.toUnmodifiableList()rejects them, so the two are not interchangeable. If you have hit a variant of this, share it below.List.of, Set.of, and Map.of throw NullPointerException for null elements, keys, or values. Validate inputs first, or choose a collection whose null policy matches the contract.
Immutable factory methods reject nulls outright, so data containing a null fails at construction. Filter or replace nulls before calling them, or use a mutable collection that accepts them.
Good to see "List.of rejects null values" written down. Handy reference for anyone working with java / collections.
Null entries cause List.of and similar factories to fail, which is easy to miss in optional-field code. Decide the null rule for each source of data before building the immutable collection.
Appreciate the write-up on "List.of rejects null values". Useful for anyone using java / collections.
Good to see "List.of rejects null values" written down. Handy reference for anyone working with java / collections.
Good to see "List.of rejects null values" written down. Handy reference for anyone working with java / collections.
Good to see "List.of rejects null values" written down. Handy reference for anyone working with java / collections.