I am developing an Android app with Android Studio, and I ran a code analysis. In many different pieces of code, the analysis suggests that some variables' "Declaration can have final modifier"
.
Indeed all those variables are set only once and it's done in the constructor, and as of today, there would be no problems if I did declare them as final
.
I was wondering if by doing so, there would be any performance improvements, if the code would run more efficiently. In other words, why is the IDE suggesting me this change?
Secondly, is it good practice to declare variables final
whenever possible? Are there cases where it could be declared as such, but I'd better not?