Java tutorial
//package com.java2s; import java.lang.reflect.Constructor; public class Main { public static Object newInstance(String paramString) { return newInstance(paramString, (Object[]) null); } public static Object newInstance(String paramString, Object[] paramArrayOfObject) { try { Constructor localConstructor = Class.forName(paramString) .getDeclaredConstructor(getArgsClasses(paramArrayOfObject)); localConstructor.setAccessible(true); return localConstructor.newInstance(paramArrayOfObject); } catch (Exception var3) { return null; } } public static Object newInstance(String paramString, Object[] paramArrayOfObject, Class<?>[] paramArrayOfClass) { try { Constructor e = Class.forName(paramString).getDeclaredConstructor(paramArrayOfClass); e.setAccessible(true); return e.newInstance(paramArrayOfObject); } catch (Exception var4) { var4.printStackTrace(); return null; } } private static Class<?>[] getArgsClasses(Object[] paramArrayOfObject) { Class[] arrayOfClass = null; if (paramArrayOfObject != null) { arrayOfClass = new Class[paramArrayOfObject.length]; for (int i = 0; i < paramArrayOfObject.length; ++i) { if (paramArrayOfObject[i] != null) { arrayOfClass[i] = paramArrayOfObject[i].getClass(); if (arrayOfClass[i] == Integer.class) { arrayOfClass[i] = Integer.TYPE; } else if (arrayOfClass[i] != String.class) { if (arrayOfClass[i] == Boolean.class) { arrayOfClass[i] = Boolean.TYPE; } else if (arrayOfClass[i] == Long.class) { arrayOfClass[i] = Long.TYPE; } } } } } return arrayOfClass; } }