Here you can find the source of valueOf(Class
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name)
//package com.java2s; /*// w w w . j a va 2 s.c o m * Copyright 2014, Francesco Jo(nimbusob@gmail.com). All rights reserved. * * Read LICENCE file in project root for licence terms of this software. */ public class Main { public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) { return valueOf(enumType, name, null); } public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name, T defaultValue) { if (null == enumType || null == name) { return defaultValue; } try { return Enum.valueOf(enumType, name); } catch (IllegalArgumentException e) { return defaultValue; } } }