IDE期待花括号后的分号[重复]

时间:2021-07-08 00:08:48

This question already has an answer here:

这个问题在这里已有答案:

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()?

为什么IDE期望“;”在返回getType()的Type(ReaderType)之后?

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

IDE放置了一个“;”在班级的开头括号之后:

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"?

为什么IDE(在本例中为Eclipse)生成“;”在Enum声明之后并显示“预期”;“返回后的类型而不是”失踪成员“?

2 个解决方案

#1


2  

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 ;

你声明一个枚举,而不是一个类,所以编译器希望在开头看到枚举元素。这些元素应该以a分隔,并以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 ;
}

#2


1  

You defined an enum. In an enum you must define enum constants before you define any methods. If you don't define any constants, you must put a semi-colon there.

你定义了一个枚举。在枚举中,您必须在定义任何方法之前定义枚举常量。如果没有定义任何常量,则必须在其中放置一个分号。

This is just how the syntax of enums is defined for Java, see section 8.9 of the Java Language Specification.

这就是为Java定义枚举语法的方法,请参阅Java语言规范的第8.9节。

#1


2  

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 ;

你声明一个枚举,而不是一个类,所以编译器希望在开头看到枚举元素。这些元素应该以a分隔,并以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 ;
}

#2


1  

You defined an enum. In an enum you must define enum constants before you define any methods. If you don't define any constants, you must put a semi-colon there.

你定义了一个枚举。在枚举中,您必须在定义任何方法之前定义枚举常量。如果没有定义任何常量,则必须在其中放置一个分号。

This is just how the syntax of enums is defined for Java, see section 8.9 of the Java Language Specification.

这就是为Java定义枚举语法的方法,请参阅Java语言规范的第8.9节。