Here you can find the source of newInstance(final Class
null
;Parameter | Description |
---|---|
type | array type |
length | array length |
@SuppressWarnings("unchecked") public static <T> T[] newInstance(final Class<T> type, final int length)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Array; public class Main { /**//from www . j a va 2 s. c o m * Create new array instance.<br> * Throws:<br> * - {@link NullPointerException} if the specified array type parameter is <code>null</code>;<br> * - {@link NegativeArraySizeException} if the specified array length is negative. * * @param type * array type * @param length * array length * @return result array */ @SuppressWarnings("unchecked") public static <T> T[] newInstance(final T type, final int length) { return (T[]) newInstance(type.getClass(), length); } /** * Create new array instance.<br> * Throws:<br> * - {@link NullPointerException} if the specified array type parameter is <code>null</code>;<br> * - {@link NegativeArraySizeException} if the specified array length is negative. * * @param type * array type * @param length * array length * @return result array */ @SuppressWarnings("unchecked") public static <T> T[] newInstance(final Class<T> type, final int length) { return (T[]) Array.newInstance(type, length); } }