Here you can find the source of newInstance(T obj, Class> argType, Object arg)
@SuppressWarnings("unchecked") public static <T> T newInstance(T obj, Class<?> argType, Object arg) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Google, Inc.// w w w. j av a 2s . c o m * 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: * Google, Inc. - initial API and implementation *******************************************************************************/ import java.lang.reflect.InvocationTargetException; public class Main { @SuppressWarnings("unchecked") public static <T> T newInstance(T obj) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { Object newObj = obj.getClass().getConstructor().newInstance(); return (T) newObj; } @SuppressWarnings("unchecked") public static <T> T newInstance(T obj, Class<?> argType, Object arg) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { Object newObj = obj.getClass().getConstructor(argType).newInstance(arg); return (T) newObj; } @SuppressWarnings("unchecked") public static <T> T newInstance(Class<?> instanceClass, Class<?> argType, Object arg) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { Object newObj = instanceClass.getConstructor(argType).newInstance(arg); return (T) newObj; } }