Does anyone have suggestions regarding getting rid of "final" modifiers on method- as well as constructor-parameters (without having to do it manually)? I've come to the conclusion that I don't want these modifiers anymore, as it clutters the method signatures (as a consequence I also have to get rid of JSR 305 @Nonnull annotations and provide an annotation on the package level).
Asked
Active
Viewed 357 times
0
-
find "final" replace it with "" :-) – sanbhat May 17 '13 at 09:05
-
... only if you are absolutely certain that it appears only on method declarations. – nakosspy May 17 '13 at 09:07
-
@sanbhat's suggestion will hit `final`s on fields and so on as well. But a find for the regular expression `\((.*)final ` and a replace with `(\1` should do it. – Tom Anderson May 17 '13 at 09:07
-
@AlexWien the OP talked about final parameters, not final methods. – Sky May 17 '13 at 09:37
-
You might have a look at http://stackoverflow.com/questions/4279420/does-use-of-final-keyword-in-java-improve-the-performance for some reasons to use final :) – Philip Helger May 17 '13 at 16:54
2 Answers
1
Using final in method signatures is a good practise.
If you still want to remove them, Go to Eclipse Window < Preferences < Java < Editor < Save actions.
If Additional Actions is checked, Click Configure < Code Style
Uncheck "use modifier final where possible".
Note : This will help you to get rid of new occurrences of final, but will not remove existing ones.
Hope this helps.

Ric
- 1,074
- 1
- 7
- 12
0
Maybe I can convince you to keep the final modifiers, as it helps the compiler to optimize your code. Otherwise just use your favourite generic text editor and replace in all files: "(final " with "" and ", final " with ", " (depending on whether you have a space or not)

Philip Helger
- 1,814
- 18
- 28
-
1Do you have evidence that there's optimization for *parameters* being final? – Jon Skeet May 17 '13 at 09:08
-
Yes, I have spaces and I your expression shouldn't have any side-effects (as I'm also using the final modifier on almost all instances, classes...). – Johannes May 17 '13 at 09:14
-
@phloc I read on various pages that the resulting byte code is exactly the same, no matter if parameters are final or not. This means that there are no optimizations done by the compiler. – Sky May 17 '13 at 10:07