Python中的枚举,支持raw的value
比如设置为字符串
class RatingType(enum.Enum): NoStar = "NoStar" OneStar = "OneStar" TwoStar = "TwoStar" ThreeStar = "ThreeStar" FourStar = "FourStar" FiveStar = "FiveStar" |
但是据说,java中,不支持enum的raw的value?
去查查
搜:
java enum raw value
参考:
java – Best way to create enum of strings? – Stack Overflow
Beginner’s Guide to Java eNum – Why and for What should I use Enum? Java Enum Examples • Crunchify
【总结】
java中对于enum,可以实现:
定义enum时,添加对应的不同类型(int,string)的值的,就是看起来好像有点麻烦而已:
public enum WeekDayEnum { Mon(1), Tue(2), Wed(3), Thu(4), Fri(5), Sat(6), Sun(7); private int index; WeekDayEnum(int idx) { this.index = idx; } public int getIndex() { return index; } } |
转载请注明:在路上 » 【已解决】Java中枚举 是否支持raw的value