在一个类中,我需要定义不同的行为,并将它们传递到一个方法中。现在,所有实例都可以安全地共享这些行为,因此我认为我可以安全地将枚举定义为静态的。
但是在我所看到的几乎所有示例中,嵌套枚举都没有被定义为静态的。那么,定义嵌套(私有)枚举的首选方式是什么?不将其定义为静态是否真的有意义呢?
public class MyClass {
private static enum Action {
READ("read"),
WRITE("write");
final String value;
Action(String value) {
this.value = value;
}
String getValue() {
return value;
}
}
// attributes, methods, constructors and so on
}