Java Reference
In-Depth Information
(
TargetType
) #i.next();
Statement
}
#i
is an automatically generated identifier that is distinct from any other identifiers
the enhanced
for
statement occurs.
If
Type
(in the
FormalParameter
production) is a reference type, then
TargetType
is
Type
; otherwise,
TargetType
is the upper bound of the capture conversion of the
type argument of
I
, or
Object
if
I
is raw.
List<? extends Integer> l = ...
for (float i : l) ...
will be translated to:
for (Iterator<Integer> #i = l.iterator(); #i.hasNext(); ) {
float #i0 = (Integer)#i.next();
...
• Otherwise, the
Expression
necessarily has an array type,
T
[]
.
Let
L
1
...
L
m
be the (possibly empty) sequence of labels immediately preceding the
enhanced
for
statement.
The enhanced
for
statement is equivalent to a basic
for
statement of the form:
T
[] #a =
Expression
;
L
1
:L
2
: ...L
m
:
for (int #i = 0; #i < #a.length; #i++) {
VariableModifiers
opt
TargetType Identifier
= #a[#i];
Statement
}
#a
and
#i
are automatically generated identifiers that are distinct from any other
identifiers (automatically generated or otherwise) that are in scope at the point
where the enhanced
for
statement occurs.
TargetType
is the type of the loop variable as denoted by the
Type
that appears in
the
FormalParameter
followed by any bracket pairs that follow the
Identifier
in