Here you can find the source of newInstance(Class> clazz, Object... args)
@SuppressWarnings("unchecked") public static <T> T newInstance(Class<?> clazz, Object... args)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Constructor; public class Main { @SuppressWarnings("unchecked") public static <T> T newInstance(Class<?> clazz, Object... args) { try {/* w w w. ja v a 2 s . co m*/ if (args == null || args.length == 0) { return (T) clazz.newInstance(); } Class<?>[] params = new Class<?>[args.length]; for (int i = 0; i < args.length; i++) { Object arg = args[i]; params[i] = arg == null ? null : arg.getClass(); } Constructor<?> ctor = clazz.getConstructor(params); return (T) ctor.newInstance(args); } catch (Throwable e) { throw new RuntimeException("Unable to create instance of [" + clazz.getName() + "]", e); } } }