Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Reconsider using Optional instead of using null #56

Open
bjhargrave opened this issue Mar 12, 2020 · 1 comment
Open

Reconsider using Optional instead of using null #56

bjhargrave opened this issue Mar 12, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@bjhargrave
Copy link
Collaborator

Returning an empty Optional is no more expensive than return null.

Using Optional can avoid numerous null checks at call sites (which can be forgotten as new code is written).

Modern JVMs are very efficient at managing short-lived objects, so using an Optional to wrap a result is not excessively costly. Of course, actual performance data to prove using null is better here can change the story, but until we have such concrete performance data, we are better off using better programming practices and not using null for control flow.

@tbitonti
Copy link
Owner

@tbitonti tbitonti added the enhancement New feature or request label Apr 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants