Java Reference
In-Depth Information
field, local variable or as the parameter of an exception handler (§
14.20
) does not obscure
a statement label with the same name.
A labeled statement is executed by executing the immediately contained
Statement
.
If the statement is labeled by an
Identifier
and the contained
Statement
completes abruptly
because of a
break
with the same
Identifier
, then the labeled statement completes normally.
In all other cases of abrupt completion of the
Statement
, the labeled statement completes
abruptly for the same reason.
14.8. Expression Statements
Certain kinds of expressions may be used as statements by following them with semi-
colons.
ExpressionStatement:
StatementExpression
;
StatementExpression:
Assignment
PreIncrementExpression
PreDecrementExpression
PostIncrementExpression
PostDecrementExpression
MethodInvocation
ClassInstanceCreationExpression
An
expression statement
is executed by evaluating the expression; if the expression has a
value, the value is discarded.
Execution of the expression statement completes normally if and only if evaluation of the
expression completes normally.
Unlike C and C++, the Java programming language allows only certain forms of ex-
pressions to be used as expression statements. Note that the Java programming lan-
guage does not allow a “cast to
void
” -
void
is not a type - so the traditional C trick of
writing an expression statement such as:
(void)... ; // incorrect!
does not work. On the other hand, the Java programming language allows all the most
useful kinds of expressions in expressions statements, and it does not require a meth-
od invocation used as an expression statement to invoke a
void
method, so such a trick