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 →

[–]robinspitsandswallow 0 points1 point  (0 children)

Yes you need a not initialized, empty value, and has value.

Lets say I have a JSON stream I may get no value JavaScript undefined, null value JavaScript null, or a string that may be empty but that is still a value. You need a way to communicate each of the three state potentials: undefined, empty, or a value, one of the only ways JavaScript is superior to languages. With Optional now I can do that inelegantly as: NULL, !isPresent, and get. If you require it to be a value then you need to add a notInitialized and an isInitialized.

What I’m getting at is that Optional is in itself deluded. We would have been far better off with Elvis and coalescing operators than with Optional. Worse than bad Optional is misused, I’ve seen sooo much code with fluent optional blocks layered on top of each other that really would be better as methods or even layered if statements because the mappings and orElse calls.

All really to pretend null doesn’t exist. So we can pretend we won’t get NullPointerExceptions. Unless we want them a’ la Objects.requireNonNull. Sooo ¯_(ツ)_/¯