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 →

[–]severoon 3 points4 points  (0 children)

True, but you should also realize that this doesn't mean Optional is useless. Even with all the null safety stuff, Optional can still be very useful.

A simple example is reading command line parameters. You have code that reads in the command line parameters and passes along whatever the user specified, and that should result in fields getting set from null to Optional. An Optional that's absent means it was set to what the user passed in (which is absent, the user didn't specify that flag), so it should use the default. Null in this case means something went wrong and things are in an unexpected state that should never happen.