Are you sure you are using the default settings? Because generally enums are indeed capitalized. Variables holding enum values should not start with a cap though.
public enum State {
UNINITIALIZED,
INITIALIZED,
STARTED,
;
}
private State state;
private void start() {
state = State.UNINITIALIZED;
...
}
`.
You may use static imports to get rid of the State. part as well, although generally I think it is better to leave it be. The enum values are constants and should be in CAPS. I've seen people change fields in enum constants during runtime, and that is not what you want (except for lazy instantiation within the class itself now and then).
In Java, names of (non-primitive) types are usually written in PascalCase. Since an enum (as a class) defines a type, it is usual to write them also in PascalCase:
发布评论
评论(5)
枚举是一种类型,枚举名称应以大写字母开头。枚举成员是常量,其文本应全部大写。
Enums are a type and the enum name should start with a capital. Enum members are constants and their text should be all-uppercase.
如果他们是自己的班级,则以大写开头;如果他们是成员,则以小写开头。
If they are their own class start with upper case, if they are members lower case.
您确定使用的是默认设置吗?因为一般来说枚举确实是大写的。不过,保存枚举值的变量不应该以上限开头。
您也可以使用静态导入来删除
State.
部分,尽管通常我认为最好保留它。枚举值是常量并且应该大写。我见过人们在运行时更改枚举常量中的字段,但这不是您想要的(除了类本身内部时不时的延迟实例化)。Are you sure you are using the default settings? Because generally enums are indeed capitalized. Variables holding enum values should not start with a cap though.
You may use static imports to get rid of the
State.
part as well, although generally I think it is better to leave it be. The enum values are constants and should be in CAPS. I've seen people change fields in enum constants during runtime, and that is not what you want (except for lazy instantiation within the class itself now and then).Java 约定文档已经 20 多年没有更新了。基本上从 Java 1.1 开始。
The Java conventions doc hasn't been updated in 20+ years. Basically since Java 1.1.
在 Java 中,(非原始)类型的名称通常以 PascalCase 形式编写。由于
enum
(作为class
)定义了一种类型,因此通常也用PascalCase来编写它们:In Java, names of (non-primitive) types are usually written in PascalCase. Since an
enum
(as aclass
) defines a type, it is usual to write them also in PascalCase: