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

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

    == is a binary equality operator.

    The left-hand operand of a binary operator appears to be fully evaluated before any part of the right-hand operand is evaluated.

    Java 11 Specification > Evaluation Order > Evaluate Left-Hand Operand First

提交回复
热议问题