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

Apache License

Declaration

@SuppressWarnings("all")
public static Object newInstance(String className, Object[] args)
        throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException,
        InstantiationException, IllegalAccessException, InvocationTargetException 

Method Source Code


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

import java.lang.reflect.*;

public class Main {

    @SuppressWarnings("all")
    public static Object newInstance(String className, Object[] args)
            throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException,
            InstantiationException, IllegalAccessException, InvocationTargetException {
        Class newoneClass = Class.forName(className);
        Class[] argsClass = new Class[args.length];
        for (int i = 0, j = args.length; i < j; i++) {
            argsClass[i] = args[i].getClass();
        }/*from  w ww  .  j  a  v  a2 s  .  c o  m*/
        Constructor cons = newoneClass.getConstructor(argsClass);
        return cons.newInstance(args);
    }
}

Related

  1. newInstance(String className, Object... args)
  2. newInstance(String className, Object... args)
  3. newInstance(String className, Object... parameters)
  4. newInstance(String className, Object... params)
  5. newInstance(String className, Object[] args)
  6. newInstance(String className, Object[] args)
  7. newInstance(String classname, Properties properties)
  8. newInstance(String clazz)
  9. newInstance(String clazzStr)