开发者

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

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?


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').


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.


If you want to leave this feature enabled in general but turn it off for a specific field, I found a simple workaround. Just declare a protected method that assigns to this field.

protected void preventFinal() { field = null; }


You can go to Project --> Properties --> Java Editor --> Save actions , Uncheck "Enable project specific settings"


There is Section called Save Actions in Eclipse Window -> Preferences -> Java -> Editor. There You can Configure Aditional actions - > (tab) code style - > Variable declarations -> edit use of final keyword.


Initialize the field with null:

private File tempDir = null;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜