Should I declare a java field 'final' when if it's not modified in code?

前端 未结 7 2008
终归单人心
终归单人心 2020-12-15 21:06

My question is mainly about performance. The compiler knows better that, for example, some variable is NOT modified after object instantiation. So, why bother with final?

相关标签:
7条回答
  • 2020-12-15 21:42

    final is used at compile-time to accept or reject your source code as valid. It shouldn't have any run-time implications.

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