I'm just curious how java works. Can someone explain why getBoolean
is called in Case 1 and not called in Case 2?
public class Main {
public static void main(String[] args) {
System.out.println("---------- Case 1 ----------");
boolean b = false;
b &= getBoolean(true);
System.out.println("---------- Case 2 ----------");
b = false;
b = b && getBoolean(true);
}
private static boolean getBoolean(boolean bool) {
System.out.println("getBoolean(" + bool + ") was called\n");
return bool;
}
}
Output:
---------- Case 1 ----------
getBoolean(true) was called
---------- Case 2 ----------