Chase said:
Does anyone know why you can only access final variables from within
an inner class inside a method? Also does anyone know why you can't
declare a static field inside of a regular inner class?
I believe the reason for the final variable only rule is to avoid
dealing with preserving the value of a changing local when its declaring
method has terminated. The inner class object can save the value of a
final variable during instance creation.
If non-final variables were allowed, but with a rule that the inner
class sees the value at instance creation time, you could have a
situation in which someone using a debugger sees one value of the
variable in the stack frame for the method, but the inner class is using
a different, older value.
In effect, the "final" is a reminder that post-creation changes in value
of the variable cannot affect the value the inner class object sees.
I have no idea about the static variable issue.
Patricia