public class JavaApplication11 {
static boolean fun() {
System.out.println("fun");
return true;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
boolean status = false;
status = status & fun();
status = fun() & status;
}
}
Will Java thought, since status is already false, it will not executed fun method? I tested, in both case, fun will be executed. But, is it guarantee across Java spec?
Short circuit evaluation does not happen here because you are using the bitwise and operation (
&) instead of the logical and operation (&&).