Java Reference
In-Depth Information
x = y * y; // now x has a value
int z = x; // okay, safe to use x
Local variables cease to exist when the flow of control reaches the end
of the block in which they were declaredthough any referenced object is
subject to normal garbage collection rules.
Apart from annotations, the only modifier that can be applied to a local
variable is final . This is required when the local variable will be accessed
by a local or anonymous inner classsee also the discussion of final vari-
ables below.
7.3.2. Parameter Variables
Parameter variables are the parameters declared in methods, construct-
ors, or catch blockssee " try, catch, and finally " on page 286 . A paramet-
er declaration consists of an optional modifier, a type name, and a single
identifier.
Parameters cannot have explicit initializers because they are implicitly
initialized with the value of the argument passed when the method
or constructor is invoked, or with a reference to the exception object
caught in the catch block. Parameter variables cease to exist when the
block in which they appear completes.
As with local variables, the only modifiers that can be applied to a para-
meter are annotations, or the final modifier.
7.3.3. final Variables
The final modifier declares that the value of the variable is set exactly
once and will thereafter always have the same valueit is immutable. Any
variablefields, local variables, or parameterscan be declared final . Vari-
 
Search WWH ::




Custom Search