I'm trying to understand concept of captured variable in Java.
I found quite detailed article about it: http://www.devcodenote.com/2015/04/variable-capture-in-java.html
and I'm not sure about bytecode part:
Similarly, for accessing local variables of an enclosing method, a hidden copy of the variable is made and kept in the inner class file from where it accesses the variable.
How can it be saved into class file (during compilation), when final primitive values may be not known in compile time?
for example:
void foo(int x){
final int y = 10 + x;
class LocalClass(){
LocalClass(){
System.out.println(y); // works fine
}
}
}
If author is wrong, are local variables copied into LocalClass's space in Method Area in runtime?