我想创建一个枚举中的私有静态最终变量,但我不断收到编译错误。有谁知道如何解决这一问题?enum中的私有静态最终变量
Multiple markers at this line
- Syntax error, insert "Identifier" to complete EnumConstantHeaderName
- Syntax error, insert "}" to complete EnumBody
class Foo {
...
public enum MyEnum {
private static final String MY_STRING = "a string I use in a constructor";
private static final String MY_OTHER_STRING = "a string I use in another constructor";
MyEnumType(1, MY_STRING),
MyEnumType2(2, MY_STRING),
MyEnumType3(3, MY_OTHER_STRING);
MyEnum(int num, String str) {
...
}
}
...
}
公约说,把你的领域关于你的方法。 – 2012-02-14 01:21:24
我实际上是在构造函数中使用字符串。 – will 2012-02-14 01:51:03
汤姆 - 你说“把你的领域放在你的方法上”是什么意思? – will 2012-02-14 01:51:29