gpt4 book ai didi

java - 在定义值之前无法在 Enum 中定义 int 变量

转载 作者:行者123 更新时间:2023-12-02 08:16:38 25 4
gpt4 key购买 nike

如果之前已经回答过这个问题,我很抱歉。我进行了搜索,但没有找到。嗨,我尝试按如下方式定义我的枚举,效果很好。

public enum MyEnum {

PRODUCT,STORE,PROMOTION,VOUCHER,URL;

private int value;


}

但是当我将其定义如下时,它无法识别 int token 。这是为什么?

public enum MyEnum  {

private int value;

PRODUCT,STORE,PROMOTION,VOUCHER,URL;

}

最佳答案

如果您阅读 documentation它说

Java requires that the constants be defined first, prior to any fields or methods. Also, when there are fields and methods, the list of enum constants must end with a semicolon.

关于java - 在定义值之前无法在 Enum 中定义 int 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17183048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com