Get enum value from enum type and ordinal

前端 未结 4 997
小蘑菇
小蘑菇 2021-01-12 08:09
public  E decode(java.lang.reflect.Field field, int ordinal) {
    // TODO
}

Assumin

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-12 08:38

    According to title, suggest

    public  E decode(Class enumType, int ordinal) 
    {
       return enumType.getEnumConstants()[ordinal];
    }
    

    to be called by

    YourEnum enumVal = decode(YourEnum.class, ordinal)
    

提交回复
热议问题