Java logical operator (&&, ||) short-circuit mechanism

后端 未结 6 2031
野的像风
野的像风 2021-02-19 06:28

As I was reading a colleague\'s Java code, I stumbled upon an army of if/else statements. In these statements, several && and || operators wer

6条回答
  •  不知归路
    2021-02-19 07:01

    Because of the precedence of && on ||, (true || true && false) this will be evaluated as (true || (true && false)) -> (true || (false)) -> true

    See the precedences rules: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

提交回复
热议问题