【发布时间】:2021-10-27 16:11:30
【问题描述】:
假设如下表达式:
public class OperatorTest {
public static void main(String[] args) {
int x = 0;
int y = 0;
if(0 == 0 || ++y == 1) {
// Some other logic here
}
System.out.println(y);
}
}
输出为 0。我理解短路运算符,因为 || 的右侧不会执行,因为左侧的计算结果为真。但是,++ 优先于短路逻辑运算符,所以 ++ 运算符不应该在逻辑运算符被评估之前评估吗?注意:我可能不需要在现实世界中这样做;这是我正在学习的认证考试。
【问题讨论】: