Java Reference
In-Depth Information
Chapter 16. Definite Assignment
Each local variable (§
14.4
) and every blank
final
field (§
4.12.4
,
§
8.3.1.2
)
must have a
defin-
itely assigned
value when any access of its value occurs.
An access to its value consists of the simple name of the variable (or, for a field, the simple
name of the field qualified by
this
) occurring anywhere in an expression except as the left-
For every access of a local variable or blank
final
field
x
,
x
must be definitely assigned before
the access, or a compile-time error occurs.
Similarly, every blank
final
variable must be assigned at most once; it must be
definitely un-
assigned
when an assignment to it occurs.
Such an assignment is defined to occur if and only if either the simple name of the variable
(or, for a field, its simple name qualified by
this
) occurs on the left hand side of an assign-
ment operator.
For every assignment to a blank
final
variable, the variable must be definitely unassigned be-
fore the assignment, or a compile-time error occurs.
The remainder of this chapter is devoted to a precise explanation of the words “definitely
assigned before” and “definitely unassigned before”.
The idea behind definite assignment is that an assignment to the local variable or blank
final
field must occur on every possible execution path to the access. Similarly, the idea behind
definite unassignment is that no other assignment to the blank
final
variable is permitted to
occur on any possible execution path to an assignment.
The analysis takes into account the structure of statements and expressions; it also provides
a special treatment of the expression operators
!
,
&&
,
||
, and
? :
, and of boolean-valued con-
stant expressions.
Except for the special treatment of the conditional boolean operators
&&
,
||
, and
? :
and of
boolean-valued constant expressions, the values of expressions are not taken into account in
the flow analysis.