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

前端 未结 7 2023
终归单人心
终归单人心 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.

提交回复
热议问题