Search code examples
javaintegerintoperatorsjava-opts

-​->-​- operator in Java


I was wondering, what does the -->-- operator do in Java?

For example, if I have the following code:

int x = 3;
int y = 3;
if (x -->-- y) {
    return true;
}

This always returns true.

Thank you!


Solution

  • In Java, -->-- is not actually an operator.

    What you wrote is actually if ((x--) > (--y)).

    And, as we know from this answer, the --y is predecrement, while the x-- is postdecrement, so therefore, this is basically if (3 > 2), which always returns true.