@Test
void test() {
boolean boolean1 = shortCircuit1 () && shortCircuit2 ();
boolean boolean2 = shortCircuit2 () && shortCircuit1 ();
System.out.println();
boolean boolean3 = shortCircuit1 () || shortCircuit2 ();
boolean boolean4 = shortCircuit2 () || shortCircuit1 ();
}
boolean shortCircuit1 () {
System.out.println("短路1");
return true;
}
boolean shortCircuit2 () {
System.out.println("短路2");
return false;
}
输出结果:
短路1
短路2
短路2
短路1
短路2
短路1
请分析一下为什么会这样.