Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 886045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:00:27+00:00 2026-05-15T13:00:27+00:00

In other words, do the following two statements behave the same way? isFoobared =

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:00:27+00:00Added an answer on May 15, 2026 at 1:00 pm

    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 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once.

    Thus, assuming boolean &, the equivalence for isFoobared &= methodWithSideEffects() is:

    isFoobared = isFoobared & methodWithSideEffects(); // no shortcircuit
    

    On the other hand && and || do shortcircuit, but inexplicably Java does not have compound assignment version for them. That is, Java has neither &&= nor ||=.

    See also

    • Shortcut “or-assignment” (|=) operator in Java
    • What’s the difference between | and || in Java?
    • Why doesn’t Java have compound assignment versions of the conditional-and and conditional-or operators? (&&=, ||=)

    What is this shortcircuiting business anyway?

    The difference between the boolean logical operators (& and |) compared to their boolean conditional counterparts (&& and ||) is that the former do not "shortcircuit"; the latter do. That is, assuming no exception etc:

    • & and | always evaluate both operands
    • && and || evaluate the right operand conditionally; the right operand is evaluated only if its value could affect the result of the binary operation. That means that the right operand is NOT evaluated when:
      • The left operand of && evaluates to false
        • (because no matter what the right operand evaluates to, the entire expression is false)
      • The left operand of || evaluates to true
        • (because no matter what the right operand evaluates to, the entire expression is true)

    References

    • JLS 15.22.2 Boolean Logical Operators &, ^, and |
    • JLS 15.23 Conditional-And Operator &&
    • JLS 15.24 Conditional-Or Operator ||
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I combine the following two statements to create a valid SQL query?
My iOS app is supposed to perform the following two tasks at the same
For two changesets X and Y of the same Mercurial repository, does following condition
In other words, when i is a map<K,V>::iterator , do the following provide the
In other words, is this Singleton implementation thread safe: public class Singleton { private
In other words, a block of code like this: (setq initial-major-mode (lambda () (text-mode)
In other words, is it correct to use: public class CustomerList : System.Collections.Generic.List<Customer> {
In other words may one use /<tag[^>]*>.*?<\/tag>/ regex to match the tag html element
In other words, if I set up SSRS Express edition will I be able
In other words, can fn() know that it is being used as $var =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.