3 ms·
> Ask me about using a Java library that could return an option type, which could be null, so you have to check for both the None return value AS WELL AS null.
by cytzol 9y ago
> Ask me about using a Java library that could return an option type, which could be null, so you have to check for both the None return value AS WELL AS null.
No, you don't -- because those are two different kinds of null!
If your library's function returns Optional.empty(), then it's because it successfully returned no value. If it returns null, though, then the library has a bug and you should crash instead of trying to continue in a known invalid state.
Without the Optional type signature, the function would return null for both of these, and your program will appear to work even though it's just suffered a bug.