对于以“is”开头的布尔变量,getter 方法的名称应该是什么

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

我有下面的成员变量 mIsMobilePresent,其中以 m 开头是我们用来识别它是成员变量的约定。

我的问题是这个变量的 getter 的名称应该是什么?

getIsMobilePresentgetIsMobilePresentisMobilePresent

首先,在Java中我们通常不会用"m"前缀来标记成员变量。

通常的(Java Bean)约定是变量被命名

boolean mobilePresent

和getter

public boolean isMobilePresent

或者,可以使用 has 前缀

public boolean hasConfiguredMobileConnections;

Where is the JavaBeans naming convention defined?

答案:Here and here.