Syntax error on token "enum", interface expected

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36500554/article/details/75783135

今天在学习的时候,新建了一个枚举类型:

enum Light {

    // 利用构造函数传参

    RED(1), GREEN(3), YELLOW(2);

    // 定义私有变量

    private int nCode;
    
    // 构造函数,枚举类型只能为私有
    private Light(int _nCode) {
        this.nCode = _nCode;
    }
    @Override
    public String toString() {
        return String.valueOf(this.nCode);
    }
}

上诉代码报错:enum cannot be resolved to a type,表示系统不识别enum。

J2SE1.5新增了enum关键字,用于定义枚举类。所以只有在jdk1.5及以后,enum才能使用。而我的eclipse前几天重新安装的,默认为1.4,所以不支持enum的使用。

解决办法:

打开工程对应的properties ——>Java Compiler, 修改 Compiler compliance level为1.5或者1.5以上。



猜你喜欢

转载自blog.csdn.net/qq_36500554/article/details/75783135
今日推荐