Here you can find the source of newInstance(Class
public static <T> T newInstance(Class<T> type)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.*; public class Main { public static <T> T newInstance(Class<T> type) { try {//from w ww . j a v a 2 s. com Constructor<T> constructor = type.getDeclaredConstructor(); if (type.getEnclosingClass() != null && constructor == null) { // inner, no static class throw new IllegalArgumentException("Inner class is not supported"); // Object enclosing = newInstance(type.getEnclosingClass()); // Constructor<T> constructor = type.getConstructor(enclosing.getClass()); // return constructor.newInstance(enclosing); } else { if (!constructor.isAccessible()) { constructor.setAccessible(true); } return constructor.newInstance(); } } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } } @SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> type, Constructor<?> constructor, Object... parameters) { try { return (T) constructor.newInstance(parameters); } catch (ReflectiveOperationException e) { return null; } } }