Java Reflection Constructor Invoke invokeConstructor(String className, Class[] paramTypes, Object[] paramValues)

Here you can find the source of invokeConstructor(String className, Class[] paramTypes, Object[] paramValues)

Description

Invokes constructor in class by given className , paramTypes and paramValues .

License

Apache License

Parameter

Parameter Description
className Class name, e.g. java.lang.Object
paramTypes Array containing parameter types
paramValues Array containing parameter values

Exception

Parameter Description
Throwable If there is some unexpected problem during execution

Return

New class instance

Declaration

public static Object invokeConstructor(String className, Class<?>[] paramTypes, Object[] paramValues)
        throws Throwable 

Method Source Code


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

import java.lang.reflect.Constructor;

public class Main {
    /**//from   w  ww .  j av  a  2 s .  c o m
     * Invokes constructor in class by given {@code className}, {@code paramTypes} and {@code paramValues}.
     * @param className Class name, e.g. {@code java.lang.Object}
     * @param paramTypes Array containing parameter types
     * @param paramValues Array containing parameter values
     * @return New class instance
     * @throws Throwable If there is some unexpected problem during execution
     */
    public static Object invokeConstructor(String className, Class<?>[] paramTypes, Object[] paramValues)
            throws Throwable {
        Class<?> clazz = Class.forName(className);
        Constructor<?> constructor = clazz.getConstructor(paramTypes);
        return constructor.newInstance(paramValues);
    }
}

Related

  1. invokeConstructor(Constructor constructor, Object... parameters)
  2. invokeConstructor(final Class clazz, final Class[] paramTypes, final Object... args)
  3. invokeConstructor(final Constructor constructor, final Object... args)
  4. invokeConstructor(final Constructor constructor, final Object[] args)
  5. invokeConstructor(final Constructor constructor, final Object... args)
  6. invokeConstructor(String className, Object... arguments)
  7. invokeConstructorOrFail(Constructor constructor, Object... args)
  8. invokeCtor(Constructor ctor, String str)
  9. invokeExactConstructor(Class klass, Object arg)