枚举解释器

public class EnumParser {

    public static Object parse(Class typeClass, Object value) {
        Class enumTmp = typeClass.asSubclass(Enum.class);
        Object[] constants = enumTmp.getEnumConstants();
        int size = constants.length;
        for (int i = 0; i < size; i++) {
            Object tmp = constants[i];
            String val = String.valueOf(((EnumBase) tmp).getValue());
            if (val.equals(String.valueOf(value))) {
                return tmp;
            }
        }
        return null;
    }
}

 

你可能感兴趣的:(枚举)