Eclipse generate getter setter tip to deal with field prefixes suffixes

Here is a nifty feature I found in Eclipse regarding generating getters and setters. Normally the names Eclipse assigns to the getter and setter methods are the field names as-is suffixed to get and set. For e.g. if you have a field called “lastName” – the getter would be getLastName() and the setter would be setLastName(). Now some people follow coding conventions by prefixing fields with a certain letter to indicate they are class level variables.  e.g. mLastName, mFirstName etc.  In such a case when Eclipse is used to generate getters/setters, then the method names become getmLastName(), setmLastName() etc.  Those names are nothing short of disgusting:

Getter Setter method name with field prefix
Getter/setter name has field prefix

Fortunately this can be easily fixed.  You can tell Eclipse that you prefix/suffix your fields in a certain way and the prefix/suffix will automatically be removed from the generated getters and setters. Click on Window -> Preferences -> Java -> Code Style.  Select Fields and click on Edit to specify the field name conventions.

Set field name conventions
Set field name convention

Now, things are looking good.

Getter/Setter without field prefix
Getter/Setter without field prefix

Eclipse, what would life be without it ?

Funny Java Constructor Quote

Saw this funny quote about constructors in the very readable Head First Java.

“You have the right to your own constructor.

If you cannot afford a constructor, one will be provided for you by the compiler.”

For someone who watches way less CSI type crap than I do, it’s a clever take on the Miranda warning. That reminds me, here’s a ridiculously hilarious image that I found which spoofs CSI :)  (Make sure you’re zoomed in enough while viewing)