Here you can find the source of tryParseEnum(Object ob, Class
public static <T extends Enum<T>> T tryParseEnum(Object ob, Class<T> enumType)
//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; } } }