List of utility methods to do Class Load
Class> | classForName(String typeName) class For Name try { return Class.forName(typeName); } catch (ClassNotFoundException e) { return null; |
Class> | classForName(String typeName) class For Name if (typeName.equals("boolean")) return boolean.class; if (typeName.equals("byte")) return byte.class; if (typeName.equals("char")) return char.class; if (typeName.equals("short")) return short.class; ... |
Class | classForNameNoThrow(String className) class For Name No Throw try { return Class.forName(className); } catch (Throwable ex) { return Object.class; |
Class> | classForNameOrNull(final String className) Call Class.forName(className), but return null if any exception is thrown. try { return Class.forName(className); } catch (final Exception e) { return null; |
Class | classForNameOrPrimitive(String name, ClassLoader loader) class For Name Or Primitive if (name == null || name.equals("") || name.equals("null") || name.equals("void")) return Void.TYPE; if (name.equals("boolean")) return Boolean.TYPE; if (name.equals("byte")) return Byte.TYPE; if (name.equals("char")) return Character.TYPE; ... |
Object | fromString(Class> clazz, String stringValue) from String if (String.class == clazz) { return stringValue; } else if (Long.class == clazz) { return Long.valueOf(stringValue); throw new IllegalArgumentException( "Instantiating " + clazz + " from string representation is not supported. Most likely an" + " incompatible version of google-http-client was used."); ... |
T | fromString(Class from String try { return Enum.valueOf(clazz, name); } catch (IllegalArgumentException e) { return null; |
T | fromString(Class from String assert (clz != null); if (value != null) { try { return Enum.valueOf(clz, value.trim()); } catch (IllegalArgumentException ex) { assert (false); return defaultVal; |
T | fromString(Class Returns the enum constant that matches the specified string, or the default value if none of the constants matches or if the string is null. try { return Enum.valueOf(enumClass, s); } catch (IllegalArgumentException e) { return defaultValue; } catch (NullPointerException e) { return defaultValue; |
T | fromString(Class from String if (text != null) { for (T value : enumType.getEnumConstants()) { if (text.equalsIgnoreCase(value.toString())) { return value; throw new IllegalArgumentException("No constant with text " + text + " found"); ... |