Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Tries to find Enum of specified name in specified class. If name's null, returns null.
     *
     * @param <E>
     * @param clazz
     * @param name
     * @return Parsed object or null
     */
    public static <E extends Enum<E>> E findEnum(Class<E> clazz, String name) {
        if (name == null) {
            return null;
        }
        try {
            return Enum.valueOf(clazz, name.toUpperCase());
        } catch (IllegalArgumentException iae) {
            return null;
        }
    }
}