views:

48

answers:

1

Hi. In constructors I very often assign to a non-existing field and choose Ctrl+1 "Create field 'memberField' in type 'CurrentType'".

The problem is that I want the field to be final by default, which it isn't. Is there a template for this quick fix somewhere? Thanks.

+3  A: 

I didn't see any obvious way to do that through code template, perhaps because this is not the Java language default.
While there are blog posts out there advocating for Data immutability by default, this is not the default style in use, as in has been previously debated in SO (or in many other SO questions)

However, you can modify the Cleanup process (occurring on each save if you want):

Java > Code Style > CleanUp > Code Style

and select Use modifier 'final' where possible.

alt text

VonC
Thanks. I waited a while to see if any other alternatives would show up but this one does the job well. As a side note I realized that you can use Ctrl+1 'assign to new field' for the constructor parameter and the assignment as well as the final field declaration will be generated. This works well with direct assignments.
disown