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

后端 未结 6 2016
野的像风
野的像风 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

    According to Java tutorials && has higher precedence over ||

    So your true || true && false would be evaluated as true || (true && false)

    And your false && true || true would be evaluated as (false && true) || true

    Resulting in an output of true in both case.

提交回复
热议问题