Java Class New Instance newInstance(Class componentType, int size)

Here you can find the source of newInstance(Class componentType, int size)

Description

new Instance

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    private static <T> T[] newInstance(Class<T> componentType, int size) 

Method Source Code

//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);
    }
}

Related

  1. newInstance(Class clazz, Class[] parameterTypes, Object[] initargs)
  2. newInstance(Class cls)
  3. newInstance(Class cls)
  4. newInstance(Class cls, Object... args)
  5. newInstance(Class clz, Class argType, K arg)
  6. newInstance(Class elementType, int len)
  7. newInstance(Class klass)
  8. newInstance(Class klass)
  9. newInstance(Class klass)