3 ms·
> But, most importantly, the fundamental issue is that all classes are optional by default in Java (indeed, that's the problem at hand). Adding an Optional clas
by simplotek 4y ago
> But, most importantly, the fundamental issue is that all classes are optional by default in Java (indeed, that's the problem at hand). Adding an Optional class doesn't really mean you can make any non-nullability assumptions about other classes, especially when using different libraries.
Perhaps it's just me, but I don't equate optional with nullable. An optional value is just the designer specifying that you may or many not specify that value, while nullable are objects which may or may not have been initialized yet.
Even though nullables have been used and abused to represent optional values, I'm not sure it's a good idea to conflate both. It would be like in C++ equating shared pointers with optional types.
- fuy 4y ago> Perhaps it's just me, but I don't equate optional with nullable. But the main usage of Optional and similar types in mainstream languages is exactly that - making the potential nullness (is that a word?) of the value explicit in the type.
- haglin 4y agoThere are multiple ways to represent an optional value, for example: 1) an empty list/array 2) throw an exception if the return value is missing. 3) -1 Optional can be used as a better alternative in all these cases. It's not just null.