Do &= and |= short-circuit in Java?
问题 In other words, do the following two statements behave the same way? isFoobared = isFoobared && methodWithSideEffects(); isFoobared &= methodWithSideEffects(); I realize I could just write up a test, but someone might know this offhand, and others might find the answer useful. 回答1: No, |= and &= do not shortcircuit, because they are the compound assignment version of & and | , which do not shortcircuit. JLS 15.26.2 Compound Assignment Operators A compound assignment expression of the form E1