Java Reference
In-Depth Information
The Iter class is local to the walkThrough method; it is not a member of
the enclosing class. Because Iter is local to the method, it has access
to all the final variables of the methodin particular the parameter objs .
It defines a pos field to keep track of where it is in the objs array.
(This code assumes that Iterator and NoSuchElementException are impor-
ted from java.util in the source that contains walkThrough .)
Members of local inner classes can hide the local variables and para-
meters of the block they are declared in, just as they can hide instance
fields and methods. The rules discussed on page 140 apply in all cases.
The only difference is that once a local variable or parameter has been
hidden it is impossible to refer to it.
5.3.1. Inner Classes in Static Contexts
We stated that an inner class is usually associated with an instance of
the enclosing class. It is possible to declare a local inner class, or an
anonymous inner class (see next section), in a static context: within a
static method, a static initialization block, or as part of a static initial-
izer. In these static contexts there is no corresponding instance of the
enclosing class, and so the inner class instance has no enclosing class
instance. In these circumstances, any attempt to use a qualified- this
expression to refer to an enclosing class's instance fields or methods will
result in a compile-time error.
 
Search WWH ::




Custom Search