0

I know that in java there is an operator hierarchy, and if you'd like one operator to act before another, you place a set of parentheses around the operator and its operand(s). However, when I try this with assignment expressions and unary increments and decrements, that is not the case.

int a = 55;
int x = a*(++a); // a will evaluate to 55*56 not 56*56

int y = 3;
int b = y*(y=10); // y will evaluate to 3*10 not 10*10

These are not the real worlds situations were I would like to use the bracket to set precedence; I just cooked these up as simple examples. I understand I could simply carry out the increment and assignment in the lines before x and b are each evaluated, but is there a reason why the precedence is not moving to the brackets here?

guy777
  • 13
  • 3

0 Answers0