noel
October 29, 2019, 11:43am
21
Could you please elaborate on that a little?
I mean, I thought that logical operators work on boolean expressions and return boolean values , whereas bitwise operators work on binary digits of integer values and return an integer.
In Java, when both operands are of type boolean, the bitwise operators &, | and ^ are overloaded to act as logical operators too.
However in such case both sides are always eagerly evaluated.
While the logical operators && and || are short-circuit evaluated:
Short-circuit evaluation, minimal evaluation, or McCarthy evaluation (after John McCarthy) is the semantics of some Boolean operators in some programming languages in which the second argument is executed or evaluated only if the first argument does not suffice to determine the value of the expression: when the first argument of the AND function evaluates to false, the overall value must be false; and when the first argument of the OR function evaluates to true, the overall value must be true.
I...