14.19
Unreachable Statements
BLOCKS AND STATEMENTS
One might expect the
if
statement to be handled in the following manner, but
these are not the rules that Java actually uses:
HYPOTHETICAL: An
if then
statement can complete normally iff at least
one of the following is
true
:
N
The
if
then
statement is reachable and the condition expression is not a
constant expression whose value is
true
.
N
The
then
statement can complete normally.
The
then
statement is reachable iff the
if
then
statement is reachable and
the condition expression is not a constant expression whose value is
false
.
HYPOTHETICAL: An
if
then
else
statement can complete normally iff
the
then
statement can complete normally or the
else
statement can com
plete normally. The
then
statement is reachable iff the
if
then
else
state
ment is reachable and the condition expression is not a constant expression
whose value is
false
. The
else
statement is reachable iff the
if
then
else
statement is reachable and the condition expression is not a constant expres
sion whose value is
true
.
This approach would be consistent with the treatment of other control structures
in Java. However, in order to allow the if statement to be used conveniently for
conditional compilation purposes, the actual rules are as follows:
ACTUAL: An
if
then
statement can complete normally iff it is reachable.
The
then
statement is reachable iff the
if
then
statement is reachable.
ACTUAL: An
if
then
else
statement can complete normally iff the
then
statement can complete normally or the
else
statement can complete nor
mally. The
then
statement is reachable iff the
if
then
else
statement is
reachable. The
else
statement is reachable iff the
if
then
else
statement
is reachable.
As an example, the following statement results in a compile time error:
while (false) { x=3; }
because the statement
x=3;
is not reachable; but the superficially similar case:
if (false) { x=3; }
does not result in a compile time error. An optimizing compiler may realize that
the statement
x=3;
will never be executed and may choose to omit the code for
that statement from the generated
class
file, but the statement
x=3;
is not
regarded as unreachable in the technical sense specified here.
298
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved