Eclipse: Adding prefix rule for fields

As I’m every now and then trying out new things in Eclipse I found out that’s quite annoying to use any kind of convention that includes prefixing your fields. In C# I always prefix my fields with “m_” so that age becomes m_Age and name becomes m_Name.

The problem with that is that when you use the getter/setter auto generator in Eclipse (right-click on a field and choose Source => Generate getters and setters…) then you end up with getters that are named getm_Age and getm_Name instead of getAge and getName.

Luckily it turns out that you can set your own prefixes in Eclipse by going to Window => Preferences => Java => Code Style and selecting the variable type that you want to edit and add your prefix.

Leave a Reply