public <E extends Enum> E decode(java.lang.reflect.Field field, int ordinal) {
// TODO
}
Assuming field.getType().isEnum()
is true
, how would I produce the enum value for the given ordinal?
public <E extends Enum> E decode(java.lang.reflect.Field field, int ordinal) {
// TODO
}
Assuming field.getType().isEnum()
is true
, how would I produce the enum value for the given ordinal?
suffices. One line; straightforward enough.
To get what you want you need to invoke
YourEnum.values()[ordinal]
. You can do it with reflection like this:UPDATE
As @LouisWasserman pointed in his comment there is much simpler way