0

当我将 a 添加switch到某个类(不包含其他内容)时,我收到以下错误(我正在使用 Eclipse):

Syntax error, insert "ClassBody" to complete ClassDeclaration

我知道问题出在这个类(以及开关)上,因为当我删除开关时,错误消失了。

我的代码:

class IsJoin {

    switch (args[0]) {

    default:
        return true;
    }

}

什么可能导致此错误?我发现的所有其他类似问题都涉及缺少括号,但这里不是这种情况。

4

1 回答 1

0

代码必须在方法或构造函数或初始化程序块中。例如,这将起作用:

public class IsJoin {
    public boolean isJoin(String[] args) {

        switch (args[0]) {

        default:
            return false;
        }   
    }
}
于 2018-07-19T16:59:15.897 回答