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

前端 未结 14 1066
误落风尘
误落风尘 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:48

    The thing here is the arithmatic operators/relational operators precedency order out of the two operators = vs == the dominant one is == (Relational Operators dominates ) as it precedes = assignment operators. Despite precedence, the order of evaluation is LTR (LEFT TO RIGHT) precedence comes into picture after evaluation order. So, Irrespective of any constraints evaluation is LTR.

提交回复
热议问题