Does Java evaluate remaining conditions after boolean result is known?

Viewed 14428

That is, if I have a statement that evaluates multiple conditions, in say a 'or' statement like so..

if(isVeryLikely() || isSomewhatLikely() || isHardlyLikely())
{
    ...
}

In the case that isVeryLikely() returns true at runtime, will isSomewhatLikely() and isHardlyLikely() execute? How about if instead of methods they were static booleans?

7 Answers

As an update for Kotlin users, you can use 'or' operator in Kotlin std library in order to check all the expressions in the if statement and not performing a short-circuit.

In the expression presented in the initial question the code in Kotlin should be:

if(isVeryLikely() or isSomewhatLikely() or isHardlyLikely()) {
    ...
}
Related