Note that two expressions do not have the same behavior if they foo()also have side effects .
If it controls the state of a program, it matters a lot if you always call it, or you call it only as a dependency on the value isEnabled.
For example, consider:
boolean foo(Object arg) {
someLocalVariable = arg;
}
It matters if you always call foo(), or if you only call it when it is isEnabledturned on, as a result, the following two expressions are completely different from each other:
if (isEnabled && foo(arg)) { ...} //local variable changes only if isEnabled==true
if (foo(arg) && isEnabled) { ...} //local variable always changes
source
share