Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Member variable prefix wrongly added to method name

I am using Eclipse to write some Java code and the naming convention that I am following uses an 'm' as a prefix to any member variables for a class. As soon as I write the member variables I like to go to Source -> Generate Getters and Setters. This generates the methods that I require. However, the method and parameter names all include this 'm' prefix too. I would like Eclipse to ignore the prefix when naming my methods and their parameters. How can I achieve this?

UPDATE: I have already tried Rich's suggestion below without any success. Currently the option is set and I have entered 'm' in the fields section. But Eclipse doesn't seem to take this into account. Clicking on the help icon on the same window brings up a notification saying that this will be taken into account when using 'code assist' and 'refactoring'. Does the 'generate getters/setters' come under code assist?

like image 713
JBug Avatar asked Jul 11 '09 16:07

JBug


People also ask

Is prefix should be used for variables and methods?

is prefix should be used for boolean variables and methods. This is the naming convention for boolean methods and variables used by Sun for the Java core packages. Using the is prefix solves a common problem of choosing bad boolean names like status or flag.

Why are prefixes needed for naming variables discuss the importance of prefixes in variable name?

The idea of variable prefixes They are used to tell the developer what kind of variable he is using. The first prefix for example is m_ and the conclusion is this variable is a member. When I learned programming we had to give the developer more information in case of a member.

What does every variable need to be prefixed with?

According to PEP 8 non-public member variables are to be prefixed with an underscore in Python (example: self. _something = 1 ).

What does M_ mean in Java?

As stated in many other responses, m_ is a prefix that denotes member variables. It is/was commonly used in the C++ world and propagated to other languages too, including Java. In a modern IDE it is completely redundant as the syntax highlighting makes it evident which variables are local and which ones are members.


1 Answers

If you go to Window->Preferences->Java->Code Style and select Fields, then Edit... and add m to the prefix list, your generated accessor methods will take the prefix into account.

like image 181
Rich Seller Avatar answered Sep 19 '22 17:09

Rich Seller