java 在枚举中初始化字符串数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5674276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Initialize an array of Strings inside an enum
提问by Deelazee
I have an Enum in Java and each of its enumeration members have a number of parameters. What I am trying to do is make one of these parameters as an array of Strings but I can't seem to be able to make the correct initialization.
我在 Java 中有一个 Enum,它的每个枚举成员都有许多参数。我想要做的是将这些参数之一作为字符串数组,但我似乎无法进行正确的初始化。
Here's what I've tried:
这是我尝试过的:
private static enum DialogType {
ACCCAT("Acccat", new String[] {"acccatid"}, "acccatText", "dlg7Matchcode", "Zutritts\nkategorie", "Text"),
private String mDialogName;
private String[] mKeyField;
private String mTextField;
private String mSelectFields;
private String mKeyFieldHeader;
private String mTextFieldHeader;
private DialogType(String dialogName, String[] keyField, String textField, String selectFields, String keyFieldHeader, String textFieldHeader) {
mDialogName = dialogName;
mKeyField = keyField;
mTextField = textField;
mSelectFields = selectFields;
mKeyFieldHeader = keyFieldHeader;
mTextFieldHeader = textFieldHeader;
}
}
However, I am getting a ton of syntactic errors. Any ideas?
但是,我收到了大量的语法错误。有任何想法吗?
回答by Heiko Rupp
Make that
做那个
public enum DialogType {
ACCCAT("Acccat", new String[] {"acccatid"}, "acccatText",
"dlg7Matchcode", "Zutritts\nkategorie", "Text");
And it should work. Note the ;
at the end of the ACCAT.
Also the enum can't be static.
它应该工作。请注意;
ACCAT 末尾的 。枚举也不能是静态的。
回答by Tim Sparg
This should do the trick - Semicolon at the end of the ACCCAT line
这应该可以解决问题 - ACCCAT 行末尾的分号
private static enum DialogType {
ACCCAT("Acccat", new String[]{"acccatid"}, "acccatText", "dlg7Matchcode", "Zutritts\nkategorie", "Text");
private String mDialogName;
private String[] mKeyField;
private String mTextField;
private String mSelectFields;
private String mKeyFieldHeader;
private String mTextFieldHeader;
private DialogType(String dialogName, String[] keyField, String textField, String selectFields, String keyFieldHeader, String textFieldHeader) {
mDialogName = dialogName;
mKeyField = keyField;
mTextField = textField;
mSelectFields = selectFields;
mKeyFieldHeader = keyFieldHeader;
mTextFieldHeader = textFieldHeader;
}
}
回答by Jeff Foster
ACCCAT("Acccat", new String[] {"acccatid"}, "acccatText", "dlg7Matchcode", "Zutritts\nkategorie", "Text");
I think you just want a semi-colon at the end of the instance declaration.
我认为您只需要在实例声明的末尾加一个分号。
I presume the enum is static because it's an inner enum of something?
我认为枚举是静态的,因为它是某个东西的内部枚举?