>>59
object-instance variables are available to the inner class methods
That's not a closure either, it's a scoping benefit. The idea behind a closure is that the environment is captured and persists, such that it can be called later. Now, I'm not a Java person, so feel free to clarify me on this, but given the following code --
class Outer {
int m_var;
class Inner {
int get() {
return m_var;
}
}
Inner get_inner() {
return new Inner();
}
}
Outer o = new Outer();
o.m_var = 1;
Inner i1 = o.get_inner();
o.m_var = 2;
Inner i2 = o.get_inner();
You're saying that the value of
i1.get() == 1 and
i2.get() == 2, correct? I was under the impression that Java did
not save the environment (and thus
i1.get() == i2.get() == 2) in which case it
isn't a closure.
I don't have a java compiler installed. How does the (syntactically correct version of this) code behave?