Java tutorial
//package com.java2s; public class Main { /** * Extracts the enum constant of the specified enum class with the * specified name. The name must match exactly an identifier used * to declare an enum constant in the given class. * * @param clazz the {@code Class} object of the enum type from which * to return a constant. * @param name the name of the constant to return. * @return the enum constant of the specified enum type with the * specified name. * * @throws IllegalArgumentException if the specified enum type has * no constant with the specified name, or the specified * class object does not represent an enum type. * * @see {@link Enum#valueOf(Class, String)} */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static Object getEnumConstant(Class<?> clazz, String name) { if (clazz == null || name == null || name.isEmpty()) { return null; } return Enum.valueOf((Class<Enum>) clazz, name); } }