So final is syntactically constrained by the fact that two different variables are actually consistent (represented by the same variable).
My understanding:
For example, this code:
Public void Test (String str) { str="ABC"; }
In fact, the execution is complete, only the original STR image file, do not affect the original variable.
An inner class is a component that belongs to an external class
classouter{PrivateString str; classinner{ Public voidTest () {System. out. println (str); } } Public Static voidMain (string[] args) {Outer.Innerinch=NewOuter ().NewInner (); This. str="AD"; Thsi.str="BC"; } }
I think that if the variables of the outer class are not final, then after the first generation of the inner class object, the result of the method execution of the inner class will change with the variable of the external class. However, the variable should be a component of the inner class, which means that you can change the inner class object generated by the arbitrary manipulation of the outer class object, which is obviously wrong. So we'll define the outer class object as final, which guarantees the consistency of the performance of the outer class and the inner class.
Not very understanding. Original link:
http://blog.csdn.net/axman/article/details/1460544
Why is the outer variable used in the inner class in Java final decoration?