2

I have below member variable mIsMobilePresent where starting with m is the convention we follow to identify that it is a member variable.

My question what should be the name of the getter of this variable?

getIsMobilePresent or getIsMobilePresent or isMobilePresent

  • you can view this: https://stackoverflow.com/questions/5322648/for-a-boolean-field-what-is-the-naming-convention-for-its-getter-setter – DhaRmvEEr siNgh Mar 14 '18 at 09:26
  • It should be `isIsMobilePresent()`, just like it should be `isIsland()` if the boolean field is called `island`. But you shouldn’t name your field `isMobilePresent`, because the type of it already indicates that it’s a boolean. Just like you shouldn’t prefix your fields with ‘m’ because that’s implicit already and any half-decent IDE will show fields in a different color or font style. Just follow the Java Coding Conventions. – Erwin Bolwidt Mar 14 '18 at 09:40

1 Answers1

0

First of all, in Java we usually don't tag member variables with an "m" prefix.

The usual (Java Bean) convention is the variable be named

boolean mobilePresent

and the getter

public boolean isMobilePresent

Alternatively, a has-prefix can be used

public boolean hasConfiguredMobileConnections;

Where is the JavaBeans naming convention defined?

Answer: Here and here.

daniu
  • 14,137
  • 4
  • 32
  • 53