img
TABLE 4-1
Highest
The Precedence of
()
[]
.
the Java Operators
++
­­
~
!
*
/
%
+
­
>>
>>>
<<
>
>=
<
<=
==
!=
&
^
|
&&
||
?:
=
op=
Lowest
However, if you want to first shift a right by b positions and then add 3 to that result,
you will need to parenthesize the expression like this:
(a >> b) + 3
In addition to altering the normal precedence of an operator, parentheses can sometimes
be used to help clarify the meaning of an expression. For anyone reading your code, a
complicated expression can be difficult to understand. Adding redundant but clarifying
parentheses to complex expressions can help prevent confusion later. For example, which of
the following expressions is easier to read?
a | 4 + c >> b & 7
(a | (((4 + c) >> b) & 7))
One other point: parentheses (redundant or not) do not degrade the performance of
your program. Therefore, adding parentheses to reduce ambiguity does not negatively
affect your program.
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home