javaoperatorsunary-operator

Does the unary operator really gets executed first?


I have this question regarding priorities. Java states that this is the priority to work out operators (from high to low):

  1. postfix unary opartors xyz++, xyz--
  2. prefixunary opartors ++xyz, --xyz
  3. typeconversion/casting
  4. "* / %
  5. "+ -
  6. << >>
  7. < <= > >=
  8. ==, !=
  9. &
  10. exclusive
  11. |
  12. &&
  13. ||
  14. ?:
  15. =, +=, -=, *=, /=, %=

Now, if you look at unary operators, they state that:

In the unary postfixnotation , unary gets executed after the expression.

Meaning that if you have:

int a = 2;
int b = a++ * 3;

int b will be 6, cause a only gets +1 after the expression.

in the unary prefixnotation, unary gets executed before the expression:

int a = 2;
int b = ++a * 3;

int b will be 9.

My question is, doesnt this mean that postfix unary operators should be at number 6 and prefix at number 1? What am I seeing wrong?


Solution

  • The "expression" that the unary operator is applied after the evaluation of is a, not any expression it might be part of.