Here you can find the source of invokeConstructor(String className, Class>[] paramTypes, Object[] paramValues)
Parameter | Description |
---|---|
className | Class name, e.g. java.lang.Object |
paramTypes | Array containing parameter types |
paramValues | Array containing parameter values |
Parameter | Description |
---|---|
Throwable | If there is some unexpected problem during execution |
public static Object invokeConstructor(String className, Class<?>[] paramTypes, Object[] paramValues) throws Throwable
//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); } }