How does java implement inner class closures?
Posted
by thecoop
on Stack Overflow
See other posts from Stack Overflow
or by thecoop
Published on 2010-05-10T17:34:30Z
Indexed on
2010/05/10
17:44 UTC
Read the original article
Hit count: 318
In Java an anonymous inner class can refer to variables in it's local scope:
public class A {
public void method() {
final int i = 0;
doStuff(new Action() {
public void doAction() {
Console.printf(i); // or whatever
}
});
}
}
My question is how is this actually implemented? How does i
get to the anonymous inner doAction
implementation, and why does it have to be final
?
© Stack Overflow or respective owner