Change defaults for Introduce Field dialog.

Is there a way of changing the default value of the "Initialize in" field of the Introduce Field refactoring dialog. Almost without fail, I want to initialize the new field in the current method, i.e. at the point where I'm doing the refactoring, but very often IntelliJ changes the default to "Field declaration".


Hi, Dan.

No, it is not possible. Initialization in field declaration is suggested only when it is possible so it could annoy only when you do lazy initialization. Is that the case? Thanks


Oops, I accidentally clicked "answered" instead of "reply".

Anyway, it annoys me every time it defaults to initialising the variable in the declaration. I never instantiate variables in this way - for various reasons, but mainly because it tends to be both less resource-efficient and harder to follow (because it combines two actions in one statement) than initialising them when required. Every time I go to extract a field and forget to change the default, it appears in the declaration, so I have to undo and then go back over it all again, re-typing the name of the extracted field. It's incredibly tedious, as I almost always forgot to correct this default behaviour. I do hope that this will be addressed in a future release.

On a related note, is it possible to set the field declaration to appear by default at the head of the class, rather than immediately before the method from which it is extracted? Again, this is part of the coding style that I follow, and it is annoying having to cut & paste the declaration each time.


Please sign in to leave a comment.