First, this is related to the lifecycle of Java objects.
When the basic data type and the referenced variable (not the referenced object) are used as local variables (this is different from the variable member variables, they are part of the object as member variables and have the same lifecycle as the object). Their lifecycle is scoped and is not affected by the lifecycle, however, the lifecycle of objects created in the same scope is not limited by the scope.
The lifecycle of a local variable is inconsistent with that of an object of a local internal class.
When a local variable of an external class is used in an internal class, it is actually called by an internal Class Object in its life cycle, when the internal class tries to access the local variables in the external method, the local variables of the external method may no longer exist, so we have to continue its life and copy it to the internal class, however, copying will bring about inconsistency, and thus the final statement must be used to ensure consistency.
Replication ensures that the lifecycle is continued, and final ensures that the reference is consistent.
References:
Http://lionheartyd.iteye.com/blog/1472407
Http://bbs.csdn.net/topics/300068105