我在Java中有一个Enum,每个枚举成员都有许多参数。我想要做的是将这些参数之一作为字符串数组,但我似乎无法进行正确的初始化。
这是我尝试过的:
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;
}
}
然而,我收到了大量的语法错误。有什么想法吗?
答案 0 :(得分:14)
制作
public enum DialogType {
ACCCAT("Acccat", new String[] {"acccatid"}, "acccatText",
"dlg7Matchcode", "Zutritts\nkategorie", "Text");
它应该有效。请注意ACCAT末尾的;
。
枚举也不能是静态的。
答案 1 :(得分:2)
这应该可以做到 - 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;
}
}
答案 2 :(得分:1)
ACCCAT("Acccat", new String[] {"acccatid"}, "acccatText", "dlg7Matchcode", "Zutritts\nkategorie", "Text");
我认为你只想在实例声明的末尾加一个分号。
我认为枚举是静态的,因为它是一个内在的枚举?