简体   繁体   English

<identifier>预期的编译错误

[英]<identifier> expected compile error

I am trying to figure out why I get a compile error on the code below: 我试图弄清楚为什么我在下面的代码上得到编译错误:

package com....;
public enum Something { //says error: <identifier> expected on this line

private String myInput;

public Something(String paramString) {
    this.myInput = paramString;
}

public String getInputName() {
    return this.myInput;
}
}

You have couple of problem with your enum declaration , first enum constructor cannot be public and second you need to add ; 你的枚举声明有几个问题,第一个enum构造函数不能公开,第二个你需要添加; before private field. 在私人领域之前。 Eg 例如

public enum Something {
    ;
    private String myInput;

    Something(String paramString) {
        this.myInput = paramString;
    }

    public String getInputName() {
        return this.myInput;
    }
}

Since it seems you are not using enumerations, change "enum" to "class". 由于您似乎没有使用枚举,请将“enum”更改为“class”。

package com....;
public class Something {

    private String myInput;

    public Something(String paramString) {
        this.myInput = paramString;
    }

    public String getInputName() {
        return this.myInput;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM