Java Class New Instance newInstance(String className, Object... args)

Here you can find the source of newInstance(String className, Object... args)

Description

new Instance

License

Open Source License

Declaration

public static Object newInstance(String className, Object... args) throws Exception 

Method Source Code


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

import java.lang.reflect.*;

public class Main {
    public static Object newInstance(String className, Object... args) throws Exception {
        return newInstance(Class.forName(className), args);
    }// w  w w  .ja va  2s  .com

    public static Object newInstance(Class<?> tClass, Object... args) throws Exception {
        Exception lastException = null;
        for (Constructor<?> constructor : tClass.getConstructors()) {
            try {
                return constructor.newInstance(args);
            } catch (Exception e) {
                lastException = e;
            }
        }
        throw lastException;
    }
}

Related

  1. newInstance(String className, Class cls)
  2. newInstance(String className, Class context)
  3. newInstance(String className, Class castTo)
  4. newInstance(String className, Class[] parmsCls, Object[] parms)
  5. newInstance(String className, Object arg1)
  6. newInstance(String className, Object... args)
  7. newInstance(String className, Object... parameters)
  8. newInstance(String className, Object... params)
  9. newInstance(String className, Object[] args)