Java Reference
In-Depth Information
double y = 3 * (1.0 / 3);
192
193
a. a ==Ð1Ñ
b. a ==null
c. a.equals(ÐÑ)
d. a == b
e. a == x
f. x == y
g. x Ċ y == null
h. x.equals(y)
Q UALITY T IP 5.2: Avoid Conditions with Side Effects
In Java, it is legal to nest assignments inside test conditions:
if ((d = b * b - 4 * a * c) >= 0) r =
Math.sqrt(d);
It is legal to use the decrement operator inside other expressions:
if (n-- < 0) . . .
These are bad programming practices, because they mix a test with another
activity. The other activity (setting the variable d , decrementing n ) is called a
side effect of the test.
As you will see in Advanced Topic 6.2 , conditions with side effects can
occasionally be helpful to simplify loops; for if statements they should always
be avoided.
Search WWH ::




Custom Search