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; //License from project: Mozilla Public License public class Main { public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) { return valueOf(enumType, name, null); }// w w w . j a v a 2s .co m public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name, T defaultValue) { T foundConstant = null; T[] constants = enumType.getEnumConstants(); for (T constant : constants) { if (constant.toString().equals(name)) foundConstant = constant; } if (foundConstant == null && defaultValue != null) foundConstant = defaultValue; return foundConstant; } }