Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent Eclipse from adding the 'final' keyword to a member variable declaration?

Tags:

When I type this

private MyKlass myklass;

and hit 'save' in Eclipse, it becomes this:

private final MyKlass myklass;

How do I stop Eclipse from doing this?

like image 351
Boris Avatar asked Aug 22 '11 12:08

Boris


People also ask

What does final mean in Java?

You use the final keyword in a method declaration to indicate that the method cannot be overridden by subclasses. The Object class does this—a number of its methods are final .

What is the purpose of declaring a variable final?

Final variables If a variable is declared with the final keyword, its value cannot be changed once initialized. Note that the variable does not necessarily have to be initialized at the time of declaration. If it's declared but not yet initialized, it's called a blank final variable.

Should we use final in Java?

In Java, the final keyword is used to denote constants. It can be used with variables, methods, and classes. Once any entity (variable, method or class) is declared final , it can be assigned only once.


2 Answers

You need to disable that option in your 'save actions'.

right click your project > properties, then go to java editor > save actions. go to 'configure', 'code style' tab, and you have it on the bottom ('private fields').

like image 50
Eran Zimmerman Gonen Avatar answered Oct 20 '22 08:10

Eran Zimmerman Gonen


Window - Preferences - Java - Editor - Save Actions - Configure... - Code Style - Use modifier final when possible

The same option can be found in Java - Code Style - Clean up.

like image 42
JB Nizet Avatar answered Oct 20 '22 09:10

JB Nizet