Why is x == (x = y) not the same as (x = y) == x?

前端 未结 14 956
误落风尘
误落风尘 2021-01-29 21:11

Consider the following example:

class Quirky {
    public static void main(String[] args) {
        int x = 1;
        int y = 3;

        System.out.println(x =         


        
14条回答
  •  没有蜡笔的小新
    2021-01-29 21:45

    It is easy in the second comparison on the left is assignment after assigning y to x (on the left) you then comparing 3 == 3. In the first example you are comparing x = 1 with new assign x = 3. It seems that there is always taken current state reading statements from left to right of x.

提交回复
热议问题