3 ms·
I'm not a Java person but isn't this just very similar to std::optional in C++? https://en.cppreference.com/w/cpp/utility/optional https://en.cppreference.com/
by dheera 4y ago
I'm not a Java person but isn't this just very similar to std::optional in C++?
https://en.cppreference.com/w/cpp/utility/optional https://en.cppreference.com/w/cpp/utility/optional
- masklinn 4y agoNo, because in C++ bare types are not nullable. In java, reference types are nullable, Optional being a reference type, Optional<T> can be null, Empty, or have a value, whereas T can be null or have a value. Also because std::optional does essentially the opposite. It’s a more efficient _ptr rather than a safer one. Optional<T> is strictly less efficient as it implies an additional allocation.
- krzyk 4y agoOK, so when valhalla lands I assume Optional will become value type (or we will have another class for that, to avoid issues with backward compatibility)
- dheera 4y ago> Optional<T> can be null, Empty, or have a value, whereas T can be null or have a value Thanks for the explanation. Wow, this sounds like a a bit of a mess, one because of the allocation, and also because it seems there are multiple ways something can be semantically null.