布尔变量名称的 Java 命名约定:writerEnabled vs writerIsEnabled
2022-09-02 23:33:49
以下哪些声明符合 Java 的命名约定?
private boolean writerIsEnabled;
// with methods like
public boolean getWriterIsEnabled()
public void setWriterIsEnabled()
或
private boolean writerEnabled;
// with methods like
public boolean getWriterEnabled()
public void setWriterEnabled()
我个人发现第一个名字“writerIsEnabled”更具可读性,特别是当你在这样的if语句中使用它时 -
if(writerIsEnabled)
{
//...
}