Rob Spoor wrote:It doesn't need to be static; it can also be a) a final local variable or final parameter in the method, or b) an instance variable of the enclosing class (or the enclosing class' enclosing class if that exists, etc).
Hi Rob,
Since "contract" variable is
reassigned several times to different objects in this example, you cannot use a final local variable or final method parameter inside the inner class as the "contract" variable. But you may use any other final local variable or a final method parameters inside the inner class as long as you keep the meaning of the "final" modifier (not reassigning it to a different value/reference).
Since this inner class has defined inside a
"static" method, you can only access the static variables of the enclosing class (I am not very good at English, but as I know this means outer class (MockClass), correct me if I am wrong) and you cannot access the instance variables of the enclosing class, because there is no reference to "this" (current object) inside a static method.
Thanks & Regards,
Manjula