Here you can find the source of fromOrdinal(Class
Parameter | Description |
---|---|
enumClass | a parameter |
value | a parameter |
T | a parameter |
@SuppressWarnings("unchecked") public static <T extends Enum<T>> T fromOrdinal(Class<T> enumClass, Integer value)
//package com.java2s; //License from project: Apache License public class Main { /**/*w w w . j av a 2 s . c o m*/ * Get the enum value from its ordinal value * * @param enumClass * @param value * @param <T> * @return */ @SuppressWarnings("unchecked") public static <T extends Enum<T>> T fromOrdinal(Class<T> enumClass, Integer value) { Enum<T>[] values = (enumClass).getEnumConstants(); if (value > values.length - 1 || value < 0) { throw new IllegalArgumentException( "Wrong value provided for the enum " + enumClass + " : " + value + "!"); } return (T) values[value]; } }