Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Java: Template for the 'create field' quick fix suggestion?

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.

like image 494
Alexander Torstling Avatar asked Aug 28 '10 12:08

Alexander Torstling


1 Answers

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

like image 126
VonC Avatar answered Oct 18 '22 09:10

VonC