Skip to content

Instantly share code, notes, and snippets.

@doom369
Created August 18, 2020 16:28
Show Gist options
  • Save doom369/c3f488c0f2be31d75e7b565e2597638b to your computer and use it in GitHub Desktop.
Save doom369/c3f488c0f2be31d75e7b565e2597638b to your computer and use it in GitHub Desktop.
public static <T extends Enum<T>> T valueOf(Class<T> enumType,
String name) {
T result = enumType.enumConstantDirectory().get(name);
if (result != null)
return result;
if (name == null)
throw new NullPointerException("Name is null");
throw new IllegalArgumentException(
"No enum constant " + enumType.getCanonicalName() + "." + name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment