What is the ampersand-peer operator used in Java?

Does Java have the &= operator? I see this code:

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

What is &= ?

+4
source share
3 answers

This is the same as:

 allReady = allReady & ace.getValue(); 

It is a little wise and. This means that you always evaluate both sides, then accept the β€œlogical” and β€œ(the result is valid only if both sides are true).

+9
source

this is a shortcut for bitwise and

 allReady = allReady & ace.getValue(); 
+3
source

This is a bitwise AND assignment operator. Equivalent:

 allReady = allReady & ace.getValue(); 
+2
source

Source: https://habr.com/ru/post/1414763/


All Articles