Java Class Load fromString(Class clz, String value, T defaultVal)

Here you can find the source of fromString(Class clz, String value, T defaultVal)

Description

from String

License

Apache License

Declaration

public static <T extends Enum<T>> T fromString(Class<T> clz,
            String value, T defaultVal) 

Method Source Code

//package com.java2s;
// Licensed to the Apache Software Foundation (ASF) under one

public class Main {
    public static <T extends Enum<T>> T fromString(Class<T> clz,
            String value, T defaultVal) {
        assert (clz != null);

        if (value != null) {
            try {
                return Enum.valueOf(clz, value.trim());
            } catch (IllegalArgumentException ex) {
                assert (false);
            }/* ww w .  ja  va2 s  .  com*/
        }
        return defaultVal;
    }

    public static <T extends Enum<T>> T fromString(Class<T> clz,
            String value) {
        assert (clz != null);

        if (value != null) {
            try {
                return Enum.valueOf(clz, value.trim());
            } catch (IllegalArgumentException ex) {
                assert (false);
            }
        }
        return null;
    }
}

Related

  1. classForNameNoThrow(String className)
  2. classForNameOrNull(final String className)
  3. classForNameOrPrimitive(String name, ClassLoader loader)
  4. fromString(Class clazz, String stringValue)
  5. fromString(Class clazz, String name)
  6. fromString(Class enumClass, String s, T defaultValue)
  7. fromString(Class enumType, String text)
  8. fromString(final Class clazz, final String value)
  9. fromString(String string, Class arrayClass)