初始化枚举内的字符串数组

发布于 2024-11-01 03:34:53 字数 868 浏览 0 评论 0原文

我有一个 Java 枚举,它的每个枚举成员都有许多参数。我想做的是将这些参数之一作为字符串数组,但我似乎无法进行正确的初始化。

这是我尝试过的:

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;
    }
}

但是,我遇到了大量语法错误。有什么想法吗?

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷…雨湿花 2024-11-08 03:34:53

做到这一点

public  enum DialogType {
    ACCCAT("Acccat", new String[] {"acccatid"}, "acccatText", 
           "dlg7Matchcode", "Zutritts\nkategorie", "Text");

并且它应该有效。请注意 ACCAT 末尾的 ;
此外,枚举不能是静态的。

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.

忘你却要生生世世 2024-11-08 03:34:53

这应该可以解决问题 - 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;
    }
}

This should do the trick - Semicolon at the end of the ACCCAT line

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;
    }
}
就此别过 2024-11-08 03:34:53
ACCCAT("Acccat", new String[] {"acccatid"}, "acccatText", "dlg7Matchcode", "Zutritts\nkategorie", "Text");

我认为你只需要在实例声明末尾有一个分号。

我认为枚举是静态的,因为它是某个东西的内部枚举?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文