The reason is that after the environment method returns, the local variable no longer exists. Therefore, a copy of the variable is created when the anonymous class is instantiated. If Java allowed the local variable to be subsequently changed, the anonymous class would only know the old value.
The way Java contradicts real closures known in other languages.
source share