The new introduced code convention require to use the "final" keyword where possible.
The question is - is there a possibility to automatically generate the variables with this keyword ? For example - I select a code fragment:
"bla"+"bla"+"bla"
and press ctrl+alt+v - the IDE generates a variable like this:
String blaString = "bla"+"bla"+"bla";
but I need it to be
final String blaString = "bla"+"bla"+"bla";
P.S. I know about inspections and the possibility "fix them all", but it can't be used everywhere as there is a lot of old code that shouldn't be refactored without reason.
A final variable is called a blank final variable if it is not initialized while declaration. Below are the two ways to initialize a blank final variable. A blank final variable can be initialized inside an instance-initializer block or inside the constructor.
Go to preferences -> Code Style -> Code Generation and enable "Make generated local variables final" in the "Final modifier" section. You can also try searching for "final" in preferences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With