Java Reference
In-Depth Information
Display 3.6
Precedence and Associativity Rules
Highest
Precedence
PRECEDENCE
ASSOCIATIVITY
From highest at top to lowest at bottom. Operators in
the same group have equal precedence.
Dot operator, array indexing, and
method invocation., [ ], ( )
Left to right
++ (postfix, as in x ++ ), −− (postfix)
Right to left
The unary operators: + , , ++ (prefix, as in ++ x),
−− (prefix), and !
Right to left
Type casts (Type)
Right to left
The binary operators * , / , %
Left to right
The binary operators +, −
Left to right
The binary operators < , > , <= , >=
Left to right
The binary operators == , ! =
Left to right
The binary operator &
Left to right
The binary operator |
Left to right
The binary operator &&
Left to right
The binary operator ||
Left to right
The ternary operator (conditional operator ) ? :
Right to left
Lowest
Precedence
The assignment operators = , *= , /= , %= , += , −= , & = , |=
Right to left
So the computer must use the associativity rules, which say that + and - are associated
left to right. So, it interprets the expression as
(bonus + ((balance * rate) / correctionFactor)) - penalty
which in turn is interpreted as the following fully parenthesized expression:
((bonus + ((balance * rate) / correctionFactor)) - penalty)
 
Search WWH ::




Custom Search