I think you totally misunderstand the nature of this issue.
In your example, since i is public and static, the publication of i should
not be an issue. Why does B need to maintain a copy of sth is public to
anybody (at least in the same scope like package)? I do not know exactly how
jvm implementers realize it. different implementers may choose to implement
it in a different way. But I think that common knowledge is that i is in
the same run time area as final variable. But no matter what, for a public
thing like that, no other classes will never need to create a local copy for
itself.
The reason that the compiler needs to create a local copy for a local class
or a pacakge level method to access a enclosing class private variables is
because directly accessing sth private or with a limited scope to you is
against at least encapsulation.
let me give you a better example to help you understand
public class A
{
private int i;
Class B
{
public int getI()
{
return i;
}
}
}
in this case, since once compiled, class A and B will be independent (not
mean that they are not coupled) classes, if we allow B to access A's private
variable, it is against encapsulation. What the compiler does is to create
a package level method to expose i from A, so B can call it.
B doesn't need to maintain a local copy for i either.
In method local class, due to sematic scop limitation, there is no such
thing can be done.