Inner class and local variables

后端 未结 6 561
无人共我
无人共我 2020-11-30 12:48

Why do I need to declare a local variable as final if my Inner class defined within the method needs to use it ?

Example :

6条回答
  •  佛祖请我去吃肉
    2020-11-30 13:15

    The answer is the two are in different scopes. So that variable could change before the inner class accesses it. Making it final prevents that.

提交回复
热议问题