Here you can find the source of newInstance(Class
private static <T> T newInstance(Class<T> type)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2013 EclipseSource 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 * * Contributors://w w w . ja v a2 s . c o m * EclipseSource - initial API and implementation ******************************************************************************/ import java.lang.reflect.*; public class Main { private static <T> T newInstance(Class<T> type) { T result = null; try { Constructor<T> constructor = type.getDeclaredConstructor(); if (!constructor.isAccessible()) { constructor.setAccessible(true); } result = constructor.newInstance(); } catch (RuntimeException rte) { throw rte; } catch (Exception exception) { String msg = "Failed to create instance of type: " + type.getName(); throw new RuntimeException(msg, exception); } return result; } }