3 ms·
The leaky null abstraction in java is orthogonal to "what does an Optional type express".
by vanjajaja1 4y ago
The leaky null abstraction in java is orthogonal to "what does an Optional type express".
- kaba0 4y agoBut the language has another often-used idiom to express a missing value, null. That’s why this was not intended for usage everywhere.
- layer8 4y agoNo, it’s not orthogonal. In Java, all reference types are implicitly optional. The explicit Optional type is only intended as a stop-gap in situations where the implicit version is especially error-prone. But in general it doesn’t make sense to have both the implicit and explicit solution, in particular when the explicit Optionals simultaneously also have the implicit optionality on top. It’s exactly the presence of the implicit optionality that makes Optional nonviable as a general-purpose optionality mechanism (in addition to its performance implications).
- vanjajaja1 4y agoIf you use the implicit optional type then you have no way to express 'not optional'. If you use the explicit optional then you can express optional/not-optional but you're stuck with a potential 3rd state. One of these problems can be fixed by convention (don't use null, ever) and the other has no fix. (unless you go down the path of annotations)