DEV Community

loading...

Discussion on: Mitigate Null Pointer Exceptions in Java with Optional class

Collapse
michelemauro profile image
michelemauro

The most important part is that using the Optional you are explicilty telling the user of your API that they may receive a value, or they may not. And both cases are clearly usable and testable.

Collapse
elmuerte profile image
Michiel Hendriks

That's basically the only use I see for using Optional, clear communication that you might not get anything.
Because for the rest it is just as unsafe.