Java Reference
In-Depth Information
9.5. Operator Precedence and Associativity
Operator precedence is the "stickiness" of operators relative to each oth-
er. Operators have different precedences. For example, relational oper-
ators have a higher precedence than boolean logic operators, so you can
say
if (min <= i && i <= max)
process(i);
without any confusion. Because * (multiply) has a higher precedence
than - (minus), the expression
3 - 3 * 5
has the value 12, not zero. Precedence can be overridden with paren-
theses; if zero were the desired value, for example, the following would
do the trick:
(3 - 3) * 5
When two operators with the same precedence appear next to each oth-
er, the associativity of the operators determines which is evaluated first.
Because + (add) is left-associative, the expression
a + b + c
is equivalent to
(a + b) + c
 
Search WWH ::




Custom Search