Remove prefix from getter

Ankit Goyal
2 min readJun 28, 2018

You love the way world code java/android program. It says all class field/variables should starts with “m” like “mId” or “mSomething” etc. What happens when you press keyboard shortcut key to generate getter/setter or constructor of your class? Obvious answer it generates them for you, correct it should also do that but what’s the name your IDE has given to them? It appends all your “m” or “s” prefix into method names. Something like below.

It looks weird to read `getmId()` or `setmSomething(String mSomething)`, not only weird but also against java code standards.

So how to solve this problem?

IDE is there to help you. If you are using any Intellij based IDEs(Intellij IDEA, Android Studio etc), this trick should work for you.

Go to File-> Other Settings-> Default Settings and search for “prefix”. You will get a popup screen something like below.

post search “prefix”

Add “m” or “s” or whatever prefix you use for your naming convention.

Just apply these changes and we are done. Now press your keyboard shortcut to generate getter, setter or constructor and it should no longer add those prefix into them.

After settings changes.

--

--