如何在java中创建具有“新”值的枚举?

ubbxdtey  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(352)

我怎样才能补充呢 new 作为java中枚举的值?
这是我的枚举:

public enum AgentProspectStatus 
{
    loose("loose"),
    on_progress("on_progress"),
    reached("reached"),
    alumni("alumni"),
    student("student"),
    new("new"); // This throws an error

    private String code;
    AgentProspectStatus(String code) 
    {
         this.code = code;
    }
}

这个 new("new") 第行显示错误:
意外标记

wribegjk

wribegjk1#

new 是java中的关键字。在java中,枚举应该用大写字母和大写字母拼写。更改案例将修复您的错误。

public enum AgentProspectStatus {
            LOOSE("loose"),
            ON_PROGRESS("on_progress"),
            REACHED("reached"),
            ALUMNI("alumni"),
            STUDENT("student"),
            NEW("new");

            private String code;
            AgentProspectStatus(String code) {
                this.code = code;
            }
        }

相关问题