Java Class New Instance newInstance(String name, ClassLoader loader)

Here you can find the source of newInstance(String name, ClassLoader loader)

Description

new Instance

License

Apache License

Declaration

public static Object newInstance(String name, ClassLoader loader) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static Object newInstance(String name) {
        return newInstance(forName(name));
    }//from   w ww  .  j  a v  a  2  s.c om

    public static Object newInstance(String name, ClassLoader loader) {
        return newInstance(forName(name, loader));
    }

    public static <T> T newInstance(Class<T> clazz) {
        try {
            return clazz.newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static Class<?> forName(String name) {
        return forName(name, null);
    }

    public static Class<?> forName(String name, ClassLoader loader) {
        try {
            if (loader == null) {
                return Class.forName(name);
            }
            return Class.forName(name, true, loader);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. newInstance(String clazz)
  2. newInstance(String clazzStr)
  3. newInstance(String cls, Class interfaceType)
  4. newInstance(String klass)
  5. newInstance(String name)
  6. newInstance(String s)
  7. newInstance(String type)
  8. newInstance(String type, Class cast)
  9. newInstance(T obj)