Java Reference
In-Depth Information
In order to precisely specify all the cases of definite assignment, the rules in this section
define several technical terms:
• whether a variable is definitely assigned before a statement or expression;
• whether a variable is definitely unassigned before a statement or expression;
• whether a variable is definitely assigned after a statement or expression; and
• whether a variable is definitely unassigned after a statement or expression.
For boolean-valued expressions, the last two are refined into four cases:
• whether a variable is definitely assigned after the expression when true ;
• whether a variable is definitely unassigned after the expression when true ;
• whether a variable is definitely assigned after the expression when false ; and
• whether a variable is definitely unassigned after the expression when false .
Here, when true and when false refer to the value of the expression.
For example, the local variable k is definitely assigned a value after evaluation of the
expression:
a && ((k=m) > 5)
when the expression is true but not when the expression is false (because if a is false,
then the assignment to k is not necessarily executed (more properly, evaluated)).
The phrase “ V is definitely assigned after X ” (where V is a local variable and X is a state-
ment or expression) means “ V is definitely assigned after X if X completes normally”. If X
completes abruptly, the assignment need not have occurred, and the rules stated here take
this into account.
A peculiar consequence of this definition is that “ V is definitely assigned after break;
is always true! Because a break statement never completes normally, it is vacuously
true that V has been assigned a value if the break statement completes normally.
The statement “ V is definitely unassigned after X ” (where V is a variable and X is a state-
ment or expression) means “ V is definitely unassigned after X if X completes normally”.
An even more peculiar consequence of this definition is that “ V is definitely unas-
signed after break; ” is always true! Because a break statement never completes nor-
mally, it is vacuously true that V has not been assigned a value if the break statement
completes normally. (For that matter, it is also vacuously true that the moon is made
of green cheese if the break statement completes normally.)
Search WWH ::




Custom Search