@Test public void testToEnum() { assertEquals(Country.SWEDEN, EnumHelper.toEnum(Country.class, "SE")); assertEquals(Gender.FEMALE, EnumHelper.toEnum(Gender.class, 1)); }
public static <T extends Enum<T>> Enum<T> toEnum(Class<T> enumClass, Object value) { assert enumClass != null; if (value == null) { return null; } try { Method method = enumClass.getMethod("toEnum", Object.class); @SuppressWarnings("unchecked") Enum<T> cast = (Enum<T>) method.invoke(null, value); return cast; } catch (Exception e) { throw new IllegalArgumentException("value " + value + " can not be converted to Enum '" + enumClass.getSimpleName() + "'", e); } }
EnumHelper { public static <T extends Enum<T>> Enum<T> toEnum(Class<T> enumClass, Object value) { assert enumClass != null; if (value == null) { return null; } try { Method method = enumClass.getMethod("toEnum", Object.class); @SuppressWarnings("unchecked") Enum<T> cast = (Enum<T>) method.invoke(null, value); return cast; } catch (Exception e) { throw new IllegalArgumentException("value " + value + " can not be converted to Enum '" + enumClass.getSimpleName() + "'", e); } } }
EnumHelper { public static <T extends Enum<T>> Enum<T> toEnum(Class<T> enumClass, Object value) { assert enumClass != null; if (value == null) { return null; } try { Method method = enumClass.getMethod("toEnum", Object.class); @SuppressWarnings("unchecked") Enum<T> cast = (Enum<T>) method.invoke(null, value); return cast; } catch (Exception e) { throw new IllegalArgumentException("value " + value + " can not be converted to Enum '" + enumClass.getSimpleName() + "'", e); } }  }
EnumHelper { public static <T extends Enum<T>> Enum<T> toEnum(Class<T> enumClass, Object value) { assert enumClass != null; if (value == null) { return null; } try { Method method = enumClass.getMethod("toEnum", Object.class); @SuppressWarnings("unchecked") Enum<T> cast = (Enum<T>) method.invoke(null, value); return cast; } catch (Exception e) { throw new IllegalArgumentException("value " + value + " can not be converted to Enum '" + enumClass.getSimpleName() + "'", e); } }  static Enum<T> toEnum(Class<T> enumClass,
			Object value); static Object toData(Enum<?> enumClass); static boolean isIdentifierAttributeOfTypeString(Class<? extends Enum<?>> enumClass); }
EnumHelper { public static <T extends Enum<T>> Enum<T> toEnum(Class<T> enumClass, Object value) { assert enumClass != null; if (value == null) { return null; } try { Method method = enumClass.getMethod("toEnum", Object.class); @SuppressWarnings("unchecked") Enum<T> cast = (Enum<T>) method.invoke(null, value); return cast; } catch (Exception e) { throw new IllegalArgumentException("value " + value + " can not be converted to Enum '" + enumClass.getSimpleName() + "'", e); } }  static Enum<T> toEnum(Class<T> enumClass,
			Object value); static Object toData(Enum<?> enumClass); static boolean isIdentifierAttributeOfTypeString(Class<? extends Enum<?>> enumClass);  }