Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有int办法确定它是否在枚举的序数范围内? 这样我就可以安然无恙theEnum.values()[ordinal];呢?
int
theEnum.values()[ordinal];
if (yourInt >= 0 && yourInt < TheEnum.values().length) { // safe }
您theEnum应该是枚举类型,而不是该枚举类型的变量。我将它大写为TheEnum, 以遵循 Java 命名约定。
theEnum
TheEnum