Java中怎样由枚举常量的ordinal值获得枚举常量对象
2016-08-19
展开全部
enum Season {
SPRING, SUMMER, AUTUMN, WINTER;
public static Season valueOf(int ordinal) {
if (ordinal < 0 || ordinal >= values().length) {
throw new IndexOutOfBoundsException("Invalid ordinal");
}
return values()[ordinal];
}
}
SPRING, SUMMER, AUTUMN, WINTER;
public static Season valueOf(int ordinal) {
if (ordinal < 0 || ordinal >= values().length) {
throw new IndexOutOfBoundsException("Invalid ordinal");
}
return values()[ordinal];
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询