public class Test {
public static void main(String[] args) {
// 邏輯運(yùn)算符執(zhí)行的是短路求值,當(dāng)左邊操作數(shù)可以推斷出表達(dá)式的值,就不再執(zhí)行 了
int x, y = 10;
if (((x = 0) == 0) || ((y = 20) == 20)) {
System.out.println(y);// 輸出10
}
// 位操作運(yùn)算不管值是如何,任何參與運(yùn)算的表達(dá)式都會被執(zhí)行求值
int a, b = 10;
if (((a = 0) == 0) | ((b = 20) == 20)) {
System.out.println(b);// 輸出20
}
}
}