On Mon, Sep 12, 2011 at 4:54 PM, clay <[email protected]> wrote:
> The "final" keyword, means that the variable reference itself can't be
> modified, but it doesn't impose or suggest any restrictions on the
> contents of the variable.
>
> You can absolutely mutate/change the contents of a final variable and
> communicate state through that between different closures or different
> parts of the application.
So, make a 2 closures and then alternate calling each where the first
increments an int, and the second prints it.
That is,
public void foo() {
int myInt = 0;
Runnable a = new Runnable() {
public void run() {
myInt++;
}
};
Runnable b = new Runnable() {
public void run() {
System.out.println(myInt);
}
};
a.run();
b.run();
}
If we had closures, you could do this, no? (Again, not being
rhetorical. This is just how I understand the situation.)
--
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en.