我想在Enum中声明静态(或非静态)变量。我需要这个,因为我想将枚举值与某些字符串关联。但我不想硬编码这些字符串。我想用String常量来使用我的应用程序范围的类。 也就是说我想写像这里面enum
declaraton,但编译时错误:如何在Java中的Enum中声明字段?
public enum MyEnum {
private static final AppConstants CONSTANTS = AppConstants.getInstance();
ONE(CONSTANTS.one()),
TWO(CONSTANTS.two());
}
我怎么能枚举把一个领域?
为什么你的AppConstants有一个get实例?它可以不是一个'enum'以及一个实例吗? – 2012-04-05 12:13:55
事实上,我使用GWT,并有'私人AppMessages MESSAGES =(AppMessages)GWT.create(AppMessages.class);' – MyTitle 2012-04-05 12:20:33