This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 201406

Summary: Automatically added final modifiers
Product: java Reporter: gualtiero65
Component: HintsAssignee: Jan Lahoda <jlahoda>
Status: REOPENED ---    
Severity: normal CC: russkiy
Priority: P3    
Version: 7.0.1   
Hardware: PC   
OS: Linux   
URL: http://twelve-programmers.blogspot.com/2008/04/automatically-add-final-modifier-to.html
Issue Type: ENHANCEMENT Exception Reporter:

Description gualtiero65 2011-08-29 16:52:55 UTC
Hi,

it would be nice to have NB to automatically add (as Hint and/or as formatting opion) final modifier to private fields, method parameters and local variables.

This is a feature I used in Eclipse. See the URL for better explanation.

Thanks,

Gualtiero
Comment 1 markiewb 2012-12-28 22:33:48 UTC

*** This bug has been marked as a duplicate of bug 125566 ***
Comment 2 runiter 2016-02-17 15:01:31 UTC
Although netbean now hints that a field can be declared as final, this is not sufficient as the original poster had requested final to be added everywhere including "local variables" and "method parameters" (as is the case in eclipse).

Also hinting alone is not sufficient. It'd be much nicer if netbean could automatically add final wherever possible (add it as an option to onSave actions instead of hint). This is also the case in eclipse.

For these reasons I'm re-opening this issue.
Comment 3 jason3421 2017-04-19 14:52:48 UTC
IntelliJ also allows this: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206185619-Auto-add-the-final-modifier-to-newly-declared-variables-values

Here is an idea for an additional feature that will help Netbeans stand even higher above Eclipse/IntelliJ. Allow the user (me!) to set a font color for non-final variables and optionally hide the final keyword all together (i.e. it's not displayed in the IDE!). E.g. say 'orange' (for me) represents all non-final variables, that's my chosen visual representation for non-final variables, done :) The 'final' attribute can then be cleanly added to the popup that already shows the variable type (cursor on variable, ctrl + space to see that popup). Thanks for reading!