Java Reference
In-Depth Information
while ((v = stream.next()) != null)
processValue(v);
Assignment operators have lower precedence than equality operators;
without the parentheses, it would be equivalent to
while (v = (stream.next() != null)) // INVALID
processValue(v);
and probably not what you want. It is also likely to be invalid code since
it would be valid only in the unusual case in which v is boolean .
Many people find the precedence of the bitwise and logical operators & ,
^ , and | hard to remember. In complex expressions you should paren-
thesize these operators for readability and to ensure correct preceden-
ce.
Our use of parentheses is sparsewe use them only when code seems
otherwise unclear. Operator precedence is part of the language and
should be generally understood. Others inject parentheses liberally. Try
not to use parentheses everywherecode becomes illegible, looking like
LISP with none of LISP 's saving graces.
Exercise 9.4 : Using what you've learned in this chapter but without
writing code, figure out which of the following expressions are invalid
and what the type and values are of the valid expressions:
3 << 2L - 1
(3L << 2) - 1
10 < 12 == 6 > 17
10 << 12 == 6 >> 17
13.5e-1 % Float.POSITIVE_INFINITY
Float.POSITIVE_INFINITY + Double.NEGATIVE_INFINITY
Double.POSITIVE_INFINITY - Float.NEGATIVE_INFINITY
0.0 / -0.0 == -0.0 / 0.0
Integer.MAX_VALUE + Integer.MIN_VALUE
 
Search WWH ::




Custom Search