Here you can find the source of newInstance(Class targetClass)
public static Object newInstance(Class targetClass) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException
//package com.java2s; /******************************************************************************* * Copyright (c) 2001, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * /*from w ww.ja v a 2 s . c o m*/ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; public class Main { private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; public static Object newInstance(Class targetClass) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException { // We want to get the default ctor, which is in the declared list. No need // to worry about inheritance because ctors are never virtual. Constructor ctor = targetClass .getDeclaredConstructor(EMPTY_CLASS_ARRAY); ctor.setAccessible(true); return ctor.newInstance(EMPTY_OBJECT_ARRAY); } }