Java String Value Of valueOf(Class enumType, String name)

Here you can find the source of valueOf(Class enumType, String name)

Description

value Of

License

Open Source License

Declaration

public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) 

Method Source Code

//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;
        }
    }
}

Related

  1. valueOf(Class cls, String s)
  2. valueOf(Class en, String name)
  3. valueOf(Class enumType, String constantName)
  4. valueOf(Class enumType, String name)
  5. valueOf(Class enumType, String name)
  6. valueOf(Class enumType, String name, T defaultValue)
  7. valueOf(final Class enumType, final String value)