3 ms·
> having a method return an Optional that will sometimes also return null Wow that's terrible. When Optional landed in Java (8?) I came to the conclusion that
by thiht 2y ago
> having a method return an Optional that will sometimes also return null
Wow that's terrible. When Optional landed in Java (8?) I came to the conclusion that the point was to use it as a contract from the developer of a method: "I return an Optional in this method so I guarantee it won't ever be null". If this is not respected, there's absolutely no reason to use Optional.
- hn_throwaway_99 2y agoTotally agree, which is why I was baffled when I saw this code. But it goes to show that if something isn't enforced at the compiler level, "clever" developers will find a way around it.