0

I am wondering if I write a line of code:

return bool1 && bool2 && bool3

where

bool1 = false
bool2 = true
bool3 = true

Would Java immediately return a false after seeing bool1 is false and do not look at bool2 and bool3? Or would it compute one by one from the left handside?

Xinyu Xiong
  • 53
  • 1
  • 6

1 Answers1

0

Java uses short circuit AND (&&).

Meaning that if bool1 is false it will not evaluate bool2 and bool3.

AminM
  • 822
  • 4
  • 11