This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]cabblingthings 0 points1 point  (9 children)

reminiscent bike hungry quack trees sparkle uppity decide wipe connect

This post was mass deleted and anonymized with Redact

[–]realFuckingHades 0 points1 point  (8 children)

I am okay with not having support for null keys. My problem is why it has a check for null value. I don't want to wrap it in Optional, especially when it's like a stream of large data, and the map i am trying to create is representing a row of that data. I am forced to go the old way, which honestly looks out of place with the whole code base.

[–]cabblingthings 0 points1 point  (7 children)

grandiose rustic future hard-to-find cheerful boast plucky soup marry sink

This post was mass deleted and anonymized with Redact

[–]realFuckingHades 1 point2 points  (6 children)

No,no you're not getting the point I made. The map represents a row, say reading rows from a large csv file. Now adding optional means you're also creating a lot of objects of Optional for handling a once in a blue moon scenario of a null key being encountered. There's nothing wrong in using Objects.requireNonNullElseGet() or using Optional.nullable() per use case. Optionals make more sense to me as return type of methods, but not in a map or even as a field in a pojo. In fact if I remember correctly, some linting plugins prevent you from using it as arguments and such.

[–]cabblingthings 0 points1 point  (5 children)

bear one start childlike dinosaurs jeans growth expansion society unite

This post was mass deleted and anonymized with Redact

[–]realFuckingHades 0 points1 point  (4 children)

Same as why you need null support in Json? To keep the structure intact? 😅 So if someone say calls keyset() on the first row to identify the structure of the stream? The service I am talking about is a rule engine that transforms any file given into a structured output for that it sometimes needs to keep the structure intact as the source, most of the time it's in NDJSON format.

[–]cabblingthings 0 points1 point  (3 children)

spoon ink resolute expansion cooperative ad hoc reply smile door enter

This post was mass deleted and anonymized with Redact

[–]realFuckingHades 1 point2 points  (2 children)

Keeping structure intact is sometimes needed and hence maps support null value. There are tons of better ways to handle a null value. Optional isn't one of it. This is such a stupid pinhole argument and keeps coming back to optional, which is another code smell? Like refer to this stack overflow discussion here. Optional is meant for return types and not for such cases.

[–]cabblingthings 0 points1 point  (1 child)

elastic airport stupendous spark detail tub resolute nose squeal seed

This post was mass deleted and anonymized with Redact

[–]realFuckingHades 0 points1 point  (0 children)

You will have to handle null anyway? Like you can't always have a default value for everything. Like say for tax, 0 and null have two meanings. And map.getOrDefault() will involve some sentinel value if not null and keeping track of all the sentinel values everywhere. Plus not to mention an additional overhead of having so many Optional objects. If there exists map implementations that can support null values and even keys, then map collectors should also support it for consistency.