【发布时间】:2019-08-14 21:13:36
【问题描述】:
我写
public class Vehicle {
public enum condition {new, used, wrecked, rebuilt, restored};
}
它不会构建,因为 new 是一个关键字。我可以改成
public enum condition {newVehicle, used, wrecked, rebuilt, restored};
但这很笨拙。有没有办法将关键字用作枚举常量?
【问题讨论】:
-
您可以使用
NEW。顺便说一句,将枚举常量写为大写字母是标准命名约定。