Here you can find the source of newInstance(Class
public static <T> T newInstance(Class<T> type, Object... args)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; public class Main { public static <T> T newInstance(Class<T> type, Object... args) { Class<?>[] classArgs = new Class<?>[args.length]; for (int i = 0; i < classArgs.length; i++) classArgs[i] = args[i].getClass(); return newInstance(type, classArgs, args); }/* ww w . j av a 2s. co m*/ public static <T> T newInstance(Class<T> type, Class<?>[] classArgs, Object... args) { Constructor<T> constructor = null; try { constructor = type.getConstructor(classArgs); } catch (SecurityException e) { e.printStackTrace(); return null; } catch (NoSuchMethodException e) { e.printStackTrace(); return null; } try { return constructor.newInstance(args); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return null; } }