Take the following example:
public void init() {
final Environment env = new Environment();
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
env.close();
}
});
}
Firstly, where is env
stored? Is it:
- copied by the compiler into a hidden member variable of the inner class that references it
- copied to, and referenced on, the heap
- left on the stack and somehow referenced there
- something else
My guess is the first option.
Secondly, do any performance issues that arise from doing this (rather than simply creating env
as a member variable of the class and referencing it as such) particularly if you are creating large numbers of such inner class constructs that reference final local variables.