Java Reference
In-Depth Information
Precedence and Associativity Rules
2
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),
!
,
~
(bitwise complement)
1
Right to left
new
and type casts (
Type
)
Right to left
The binary operators
*
,
/
,
%
Left to right
The binary operators
+
,
-
Left to right
The binary operators
<<
,
>>
,
>>>
(shift operators)
1
Left to right
The binary operators
<
,
>
,
<=
,
>=
,
instanceof
Left to right
The binary operators
==
,
!=
Left to right
The binary operator
&
Left to right
The binary operator
^
(exclusive or)
1
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
The assignment operators
=
,
*=
,
/=
,
%=
,
+=
,
-=
,
&=
,
|=
,
^=
,
<<=
,
>>=
,
>>>=
Right to left
1
Not discussed in this topic.