The Java tutorials here mention that &=
is an assignment operator but doesn't seem to mention what it does.
What does &=
do?
a &= x
is equivalent to
a = (type of a)(a & x)
which in turn is a
a
and x
in the case where a
and x
are integers or aa
and x
being boolean
s (which means that x
will be evaluated in any case here, even if a
is false
).There are several other binary operators which can be used with similar semantics, like +=
, -=
, *=
, /=
, %=
, |=
, <<=
, ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With