Skip to content

Conversation

@nielspardon
Copy link
Member

This PR makes parameters and local variables final if possible and adds corresponding PMD checks so any new parameters or local variables will be declared final if they could be final.

<rule ref="category/java/codestyle.xml/FieldDeclarationsShouldBeAtStartOfClass" />
<rule ref="category/java/codestyle.xml/FinalParameterInAbstractMethod" />
<rule ref="category/java/codestyle.xml/LocalVariableCouldBeFinal" />
<rule ref="category/java/codestyle.xml/MethodArgumentCouldBeFinal" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am definitely in favor of the first two FinalParameterInAbstractMethod and LocalVariableCouldBeFinal, but I am less convinced about introducing MethodArgumentCouldBeFinal. It looks like a lot noise is introduced in this PR by bringing in that rule. Considering that usage of final doesn't actually prevent mutation of the object, just reassignment to a new object, it doesn't seem that useful.

We also already have the immutables library to protect against mutation for the classes for which that matters.

Happy to be convinced though if there is a compelling reason to switch to using final.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants