Java Class New Instance newInstance(Class interfaceDefinition, String className, ClassLoader classLoader)

Here you can find the source of newInstance(Class interfaceDefinition, String className, ClassLoader classLoader)

Description

new Instance

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
private static <I> I newInstance(Class<I> interfaceDefinition, String className, ClassLoader classLoader) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    @SuppressWarnings("unchecked")
    private static <I> I newInstance(Class<I> interfaceDefinition, String className, ClassLoader classLoader) {
        try {//w  ww.  j ava  2 s.  c  o m
            Class<I> spiClass;

            if (classLoader == null) {
                spiClass = (Class<I>) Class.forName(className);
            } else {
                spiClass = (Class<I>) classLoader.loadClass(className);
            }

            return spiClass.newInstance();
        } catch (ClassNotFoundException x) {
            throw new java.lang.RuntimeException("Provider " + className + " not found", x);
        } catch (Exception ex) {
            throw new java.lang.RuntimeException("Provider " + className + " could not be instantiated: " + ex, ex);
        }
    }
}

Related

  1. newInstance(Class cls)
  2. newInstance(Class cls, Map, Constructor> cache)
  3. newInstance(Class componentType, int... dimensions)
  4. newInstance(Class entity)
  5. newInstance(Class theClass, Class expected)
  6. newInstance(Class aClass, Object... args)
  7. newInstance(Class arrayComponentClass, T value)
  8. newInstance(Class beanClass)
  9. newInstance(Class c)