Why is this Java operator precedence being ignored here?

前端 未结 7 1442
栀梦
栀梦 2020-12-10 18:13

The following code prints out \"3\", not \"4\" as you might expect.

public class Foo2 {
    public static void main(String[] args) {
        int a=1, b=2;            


        
7条回答
  •  时光取名叫无心
    2020-12-10 19:01

    This isn't a matter of precedence, it's a matter of the definition of the operator. By definition the postfix operator executes after the variable is used in the enclosing expression.

提交回复
热议问题