Is the left-to-right order of operations guaranteed in Java?

后端 未结 10 1231
温柔的废话
温柔的废话 2021-01-04 10:16

Consider this function:

public static final int F(int a, int b) {
    a = a - 1 + b;
    // and some stuff
    return a;
}

Is it required

10条回答
  •  鱼传尺愫
    2021-01-04 10:35

    According to here:

    Operators on the same line have equal precedence. When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first. All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.

    So yes.

提交回复
热议问题