It is generally a good idea to restrict access to your variables as much as reasonably possible. For example make things private
instead of public
and make variables final
if they aren't supposed to change. I believe the same applies to method parameters, but I find actual practice of this to be extremely rare.
For example, no IDEs that I know of offer warnings for finality of method parameters, even though you should be able to tell easily if the parameter can be made final. Even core Java libraries don't make their method parameters final, even though they could; and I find it pretty rare for a 3rd party library to do this either.
Overall the benefits here are certainly relatively low, given that the scope is so small. Does it give enough benefits though to justify as a coding standard?
final
parameter, you can simply omitfinal
and the code will work with the same behavior.final
is about what you cannot do, and thus what assumptions you can make. So instead you'd want examples of confusing or broken code that would have been disallowed had the parameter beenfinal
.