且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java中的增量前和增量后行为

更新时间:2022-05-20 05:21:41

由于'/'的优先级高于'+'的优先级,因此先进行评估.

Since '/' has higher precedence than '+' it is evaluated first.

否,表达式是从左到右求值的-然后使用优先级规则将每个操作数关联起来.

No, expressions are evaluated left to right - each operand is then associated using precedence rules.

因此您的代码等同于:

int temp1 = j--; //1
int temp2 = ++j; //1
int temp3 = j++; //1
int result = temp1 + (temp2 / temp3); //2