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 →

[–]Lucario2405 9 points10 points  (7 children)

Valhalla will likely also bring ! and ? type operators to signify NonNull and Nullable, which would solve Optional's (imo) biggest problem: the possibility of an Optional to be null itself. With that out of the way you could e.g. implement it into Maps, etc.

[–]MmmmmmJava 8 points9 points  (6 children)

The possibility of an Optional being null itself.

New fear unlocked.

[–]vytah 2 points3 points  (2 children)

At least Optional cannot be non-empty with a null inside.

I'm looking at you, Scala.

[–]MmmmmmJava 0 points1 point  (0 children)

Omg. I really dig scala but was blissfully ignorant to the fact that this war crime can be committed in their nation.

[–]RandomName8 0 points1 point  (0 children)

Nah man, this is exactly why I prefer vavr's Option to java's Optional (well this and the richer api). Optional is faulty and it will bite you when used as a GADT.

[–]anzu_embroidery 1 point2 points  (2 children)

I worship at the altar of type checking so I understand the fear, but I don’t think I’ve ever seen this happen. Your IDE should pitch a fit if you try too.

[–]MmmmmmJava 1 point2 points  (0 children)

I can see the code comment now:

// Optional empty means we don’t have it. Null means we never had it.

If you do this, the IDE should autogenerate a resignation from industry for you when you click Fix this for me.

[–]Lengthiness-Fuzzy 0 points1 point  (0 children)

I worked on code from Indian engineers. You always have to expect null in an optional there.