2

In Java, the && and || are short circuit. Thus, they do not evaluate their second operand if not necessary (e.g. false && a, true || b).

What about the &= operator? Is it short circuit as well?

Claas Wilke
  • 1,951
  • 1
  • 18
  • 29

2 Answers2

2

No, &= is not a boolean operator and as such it does not short-circuit anything, it's a bitwise assignment operator.

It essentially implies assigning first operand with bitwise & of first and second operands.

Quick demo

int i = 01;
int ii = 10;
System.out.println(i &= ii); // assigns i with i & ii and sends i to print stream
i = 01;
ii = 11;
System.out.println(i &= ii);

Output

0
1
Mena
  • 47,782
  • 11
  • 87
  • 106
1

No, it's not.

There was a thread a while back about why doesn't a &&= operator exist. That could've been a short-circuit operator, if it made sense to have it.

Kayaman
  • 72,141
  • 5
  • 83
  • 121