New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow nulls in EntryStream.toMap() and similar #149
Comments
Why do you want to have a null key or value? Just curious about |
Here you are some examples:
So, when I have full control on code, in particular on the functions that use the returned map, the problem can be workarounded:
Nevertheless, most of times these maps are used for serialization/marshalling/persistence, so I can't use non-pojo objects (and Optional is an immutable non-serializable monad).
Even if this is not a great issue, it's still annoying. I understand, theoretically speaking, the java 8 filosophy against nulls, but in practice nulls spread in every single piece of code, and in most cases are unavoidable just because null it's a language property. |
Note that |
Right, you stated it in doc. But I suppose it's a preemptive statement, probably conservative for future changes, since Removing the limitation on |
@mmariotti I have read the answers on : Java 8 NullPointerException in Collectors.toMap |
On a first glimpse, I see that |
After rethinking I doubt that modifying even Another problem is the merging version when custom merger is provided. Merging typically is delegated to An end-user alternative would be to create a |
Hello,
I understand the reason, but I think this is too limitating.
Even when I'm dealing with parallel streams, I'm not sure it's useful:
ConcurrentHashMap
already throwsNullPointerException
if any key or value is null (by doc).When dealing with sequential streams instead, I see no straight way collecting to a null-tolerant map.
So, I want to propose some solution:
EntryStream.toCustomMap()
EntryStream.toNullTolerantMap()
Thank you!
The text was updated successfully, but these errors were encountered: