Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Putting code in the .orElse that has a side effect that can affect performance #4199

Merged
merged 2 commits into from
Nov 9, 2023

Conversation

jlerbsc
Copy link
Collaborator

@jlerbsc jlerbsc commented Nov 9, 2023

When using Optionals, whatever code is provided in the .orElse will be executed everytime the Optional is evaluated. Sometimes people make the mistake of putting code in the .orElse that has a side effect that can affect performance or can result in bugs. In these cases .orElseGet should be used as it defers execution until the Optional actually evaluates to empty and the .orElseGet needs to be run.

@jlerbsc jlerbsc merged commit 31a6717 into javaparser:master Nov 9, 2023
31 of 32 checks passed
@jlerbsc jlerbsc added this to the next release milestone Nov 9, 2023
@jlerbsc jlerbsc added the PR: Changed A PR that changes implementation without changing behaviour (e.g. performance) label Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Changed A PR that changes implementation without changing behaviour (e.g. performance)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant