Here you can find the source of newInstance(Class
public static <T> T newInstance(Class<T> type, Class<?>[] parameterTypes, Object[] args) throws Exception
//package com.java2s; //License from project: Apache License import java.lang.reflect.Constructor; public class Main { public static <T> T newInstance(Class<T> type, Class<?>[] parameterTypes, Object[] args) throws Exception { Constructor<T> constructor = getConstructor(type, parameterTypes); constructor.setAccessible(true); return constructor.newInstance(args); }// w w w . j a v a 2 s. c o m private static <T> Constructor<T> getConstructor(Class<T> type, Class<?>[] parameterTypes) throws Exception { try { return type.getConstructor(parameterTypes); } catch (NoSuchMethodException e1) { try { return type.getDeclaredConstructor(parameterTypes); } catch (NoSuchMethodException e2) { throw e2; } } } }