[
https://issues.apache.org/jira/browse/LANG-1136?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14536422#comment-14536422
]
Cimballi commented on LANG-1136:
--------------------------------
The code of the method would be something like :
public static <T extends Enum<T>, E extends Enum<E>> T valueOf(final Class<T>
enumType, final E value) {
if (value == null) {
return null;
}
return Enum.valueOf(enumType, value.name());
}
You may also have 2 versions, the one above and another one which does not
throw an exception if enum is not found but returns null instead.
> Add a method in EnumUtils to 'translate' an enum value
> ------------------------------------------------------
>
> Key: LANG-1136
> URL: https://issues.apache.org/jira/browse/LANG-1136
> Project: Commons Lang
> Issue Type: Wish
> Reporter: Cimballi
> Priority: Minor
> Fix For: Discussion
>
>
> Add a method in EnumUtils to 'translate' an enum value.
> Example :
> Enum1
> Enum2
> Object.enum2
> Enum1 getEnum(Enum1.class, Object.enum2);
> If enum2 is null, returns 2, else returns the Enum1 with the same name as
> Object.enum2, throws exception if no such Enum1.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)