我正在尝试创建以下枚举,但是Eclipse出现以下错误:


  语法错误,插入“;”完成ClassBodyDeclarations


码:

public class SE {

    private enum Separator {
        COMMA(","),
        SEMICOLON(";"),
        COLON(":");

        private String separator;
    }

}


更新:

//still receiving the same error

public class ParameterParser {

private enum Separator {

    COMMA(","),
    SEMICOLON(";"),
    COLON(":");

    private String mSeparator;

    private Separator(String separator) {
        // TODO Auto-generated method stub
        this.mSeparator = separator;
    }

    public String getSeparator() {
        return this.mSeparator;
    }
}
}

最佳答案

添加一个构造函数

private Separator(String separator) {
    this.separator = separator;
}

10-06 09:11