When Java evaluates a conjunction ( && ), does it eval exp2 if exp1 is false?

前端 未结 5 655
谎友^
谎友^ 2020-12-07 04:08

I\'m wondering if it\'s guaranteed that in a Java program, the boolean expression on the right of a conjunction (exp2 above) will NOT be evaluated as long as the expression

5条回答
  •  旧时难觅i
    2020-12-07 04:52

    If you use && or ||, java will use short-circuit evaluation (ie not evaluate the second expression unless it needs to)

    If you use & or |, java will always evaluate the second expression, even if the first was true

提交回复
热议问题