Here you can find the source of newInstance(Class
@SuppressWarnings("unchecked") private static <T> T[] newInstance(Class<T> componentType, int size)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2006//from w w w . j a v a2 s. c o m * Thomas Hallgren, Kenneth Olwing, Mitch Sonies * Pontus Rydin, Nils Unden, Peer Torngren * The code, documentation and other materials contained herein have been * licensed under the Eclipse Public License - v 1.0 by the individual * copyright holders listed above, as Initial Contributors under such license. * The text of such license is available at www.eclipse.org. *******************************************************************************/ import java.lang.reflect.Array; public class Main { @SuppressWarnings("unchecked") private static <T> T[] newInstance(Class<T> componentType, int size) { return (T[]) Array.newInstance(componentType, size); } @SuppressWarnings("unchecked") private static <T> T[] newInstance(T[] template, int size) { return (T[]) Array.newInstance(template.getClass().getComponentType(), size); } }