Java Enum Parse tryParseEnum(Object ob, Class enumType)

Here you can find the source of tryParseEnum(Object ob, Class enumType)

Description

try Parse Enum

License

Apache License

Declaration

public static <T extends Enum<T>> T tryParseEnum(Object ob, Class<T> enumType) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static <T extends Enum<T>> T tryParseEnum(Object ob, Class<T> enumType) {
        return tryParseEnum(ob, enumType, null);
    }//from w w w. j ava  2  s. c  om

    public static <T extends Enum<T>> T tryParseEnum(Object ob, Class<T> enumType, T defaultVal) {
        if (ob == null)
            return defaultVal;
        try {
            return (T) Enum.valueOf(enumType, String.valueOf(ob));
        } catch (Exception e) {
            return defaultVal;
        }
    }
}

Related

  1. tryParseEnum(Class c, String string)