OR运算符 - 哪种语句更有效?

att*_*ofi 0 java

当我使用OR运算符时,只有一个表达式必须为true.第一个if语句是否更有效,因为java只检查第一个表达式?或者java检查两者?

public class Test {
    public static void main(String args[]) {

        boolean test = true;

        if (test || calculate()) {
            // do something
        }

        if (calculate() || test) {
            // do something
        }
    }

    public static boolean calculate() {
        // processor-intensive algorithm
    }
}
Run Code Online (Sandbox Code Playgroud)

Era*_*ran 9

if (test || calculate())
Run Code Online (Sandbox Code Playgroud)

绝不会打电话calculate()的时候test是真实的,因为||运营商短路,所以这种说法是当更有效的test是真实的.