3 ms·
A consistent API written with Optional should make it such that if an Optional is returned, then a null value could have been returned. If an Optional is not r
by craigching 11y ago
A consistent API written with Optional should make it such that if an Optional is returned, then a null value could have been returned. If an Optional is not returned (including for references), then you can assume that null will not be returned. This is a contract that can be documented as part of the API documentation.
To me, this is much clearer than having to guess on every call and I would prefer this use of Optional or not in an API to an API without Optional and having to check everything.