Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make classes final by default in Eclipse?

Tags:

java

eclipse

Is there a way to make classes final by default in Eclipse? i.e: on save actions, or in the create new class dialog?

like image 325
GNUnit Avatar asked Jun 18 '11 16:06

GNUnit


2 Answers

This truly is a hack, but what you can do in your eclipse settings is set the following code template:

Explained below

Under Java > Code Style > Code Templates > Code > New Java Files, you can add the final keyword right before ${type_declaration}.

The caveat is that the final checkbox is no longer properly functional, but if you are someone that blows through the New Class dialog before clicking a box in the first place, then it may be a lesser evil to remove final in the actual code afterwards in the 10% of cases you need it.

The other caveat is that the first line of the class will look like final public MyClass; while still valid, it is not the more idiomatic public final MyClass.

like image 145
Alex Gittemeier Avatar answered Nov 08 '22 22:11

Alex Gittemeier


Click on final check box in new class dialog.

enter image description here

Also take a look at this: How to create a custom 'new class wizard' for Eclipse?

like image 44
Harry Joy Avatar answered Nov 08 '22 20:11

Harry Joy