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

后端 未结 10 1219
温柔的废话
温柔的废话 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:39

    Yes:

    http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.7

    The JVM will intepret

    x = input - 1 + q;
    

    as

    x = (input - 1) + q;
    

提交回复
热议问题