Search code examples
javanaming-conventionsgetter-setter

What should be the name of getter method for a boolean variable starting with `is`


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


Solution

  • 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.