Jothi
Jothi

Reputation: 15090

Why method parameters needs to be set as final?

I have enabled Checkstyle for my project. It is showing yellow mark on method parameters and requesting to set it as final. Why? What is the purpose? If not specified what will be the problem?

Upvotes: 5

Views: 5695

Answers (2)

user6273792
user6273792

Reputation: 11

Remove FinalParameters from your CheckStyle declaration. http://checkstyle.sourceforge.net/config_misc.html#FinalParameters

Upvotes: 1

Balazs Zsoldos
Balazs Zsoldos

Reputation: 6046

In case there is a rule in Checkstyle, normally the answer is there as well: http://checkstyle.sourceforge.net/config_misc.html

In this case:

Changing the value of parameters during the execution of the method's algorithm can be confusing and should be avoided. A great way to let the Java compiler prevent this coding style is to declare parameters final.

Upvotes: 4

Related Questions