Java 8’s new Optional type is worthless
W. Brian Gourlie

I agree it would be nice to have the compiler verify that you handle both present/non-present conditions.

But the NoSuchElementException means that *you* are violating Optional’s contract — or at least its expected use as I understand it — because you haven’t checked if the value is present. And if the function returns null despite its signature having an Optional return type, then the programmer of that function has also broken Optional’s contract.

Either way, it reflects a problem not in the Optional class, but in its users.

Show your support

Clapping shows how much you appreciated aliteralmind-medium’s story.