如何在Java中创建具有“新”值的ENUM?

如何将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")行显示错误:

意外的标记

回答

new是Java 中的关键字。在 Java 中,枚举应拼写为大写和 case_snake。更改大小写将修复您的错误。

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;
            }
        }


以上是如何在Java中创建具有“新”值的ENUM?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>