Search code examples
javaoperatorscode-analysis

What is the ampersand-equals operator used for in Java?


Does Java have an &= operator? I'm seeing this code:

boolean allReady = true;            
for(Entry<String,Boolean> ace : factory.readyAces.entrySet()) {
    allReady &= ace.getValue();

What is &=?


Solution

  • It's the same as:

    allReady = allReady & ace.getValue();
    

    This is a bit-wise and. It means you always evaluate both sides, then take the "logical and" (result is only true if both sides are true).