Parameters which are not marked as final
can be changed, in the same manner as local variables. This is usually not desireable, but the language permits it. Marking the parameter as final
prevents this.
Using final :
- clearly communicates your intent
- allows the compiler and virtual machine to perform minor optimizations
- clearly flags items which are simpler in behaviour - final says, "If you are looking for complexity, you won't find it here."
From http://www.javapractices.com/topic/TopicAction.do?Id=23
The answers to the SO question http://stackoverflow.com/questions/154314/when-to-use-final explain why it is a good idea to declare parameters final
. Clearly, the people who created the PMD default ruleset agree with this.
However, use of final
is not mandatory in this situation, and not required by some Java style guides. If you think that final
makes your code untidy and verbose, you are free to tailor the PMD ruleset to exclude this rule.
To be honest, I don't think there's anything much to discuss here. Besides, SO is not a suitable forum for "discussion" and airing one's grievances about tools, etc. Try http://programmers.stackexchange.com
oh really, let's look at PMD's own source code:
http://pmd.sourceforge.net/xref/net/sourceforge/pmd/ant/PMDTask.html
among 20 or so method parameters, ZERO parameters are final.