Inner class and local variables

后端 未结 6 550
无人共我
无人共我 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 12:53

    According to Java memory model use of final variable guarantees that the final variable are always initialized. We get error when we try to use local variable without initialization. using final guarantees the inner class that local variable which is been used is initialized.

提交回复
热议问题