Java Class New Instance newInstance(String className)

Here you can find the source of newInstance(String className)

Description

new Instance

License

Apache License

Declaration

public static Object newInstance(String className) 

Method Source Code

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

public class Main {
    public static Object newInstance(String className) {
        return newInstance(fetchClass(className));
    }/*from  w  w  w  .ja va 2s .c  om*/

    public static <T> T newInstance(Class<T> clazz) {
        if (clazz == null) {
            return null;
        }
        try {
            return clazz.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Class<?> fetchClass(String className) {
        try {
            return Class.forName(className);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. newInstance(ProceedingJoinPoint thisJoinPoint, Class clazz, Object... newArgs)
  2. newInstance(String aclass)
  3. newInstance(String className)
  4. newInstance(String className)
  5. newInstance(String className)
  6. newInstance(String className)
  7. newInstance(String className)
  8. newInstance(String className)
  9. newInstance(String className)