Variable used in lambda expression should be final or effectively final

后端 未结 7 755
抹茶落季
抹茶落季 2020-11-22 07:54

Variable used in lambda expression should be final or effectively final

When I try to use calTz it is showing this error.

相关标签:
7条回答
  • 2020-11-22 08:53

    Although other answers prove the requirement, they don't explain why the requirement exists.

    The JLS mentions why in §15.27.2:

    The restriction to effectively final variables prohibits access to dynamically-changing local variables, whose capture would likely introduce concurrency problems.

    To lower risk of bugs, they decided to ensure captured variables are never mutated.

    0 讨论(0)
提交回复
热议问题