gismo gismo - 3 months ago 20
Java Question

IDE expects semicolon after curly braces

I have this code with parametrized Interfaces:

public enum CLIError implements IUIErrorEnum<CLIError>, IErrorEnum<CLIError> {
@Override
public ReaderType getType() {
return ReaderType.CLI;
}


Why does the IDE expect a ";" after the returning Type (ReaderType) of getType()?

The IDE placed a ";" after the opening bracket of the class:

public enum CLIError implements IUIErrorEnum<CLIError>, IErrorEnum<CLIError> {
;
@Override


Why does the IDE (Eclipse in this case) generate the ";" after the Enum declaration and display a "expected ";" after the return type instead of a "missing members"?

Answer

You are declaring an enum, not a class, so the compiler expects to see enum elements at the beginning. These elements should be separated by , and end with a ;

public enum CLIError implements IUIErrorEnum<CLIError>, IErrorEnum<CLIError> {
    ELEMENT_1,
    ELEMENT_2,
    LAST_ELEMENT;

    @Override
    public ReaderType getType() {
        return ReaderType.CLI;
    }
}

Even if you don't declare any enum elements, the ; is mandatory.

Note that if you don't declare a method in the enum, the ; can be omitted.

public enum CLIError {
    // compiles without ;
}

or

public enum CLIError {
    ELEMENT_1,
    ELEMENT_2,
    LAST_ELEMENT
    // compiles without ;
}
Comments