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

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

Description

Creates and returns an array of the given type and size.

License

Apache License

Declaration

@SuppressWarnings("unchecked")
public static <T> T[] newInstance(Class<? extends T> componentType, int length) 

Method Source Code


//package com.java2s;
/*//from w  w  w.ja  va 2 s .  c  o m
 * Copyright 2010-2012 Roger Kapsi
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

import java.lang.reflect.Array;

public class Main {
    /**
     * Creates and returns an array of the given type and size.
     */
    @SuppressWarnings("unchecked")
    public static <T> T[] newInstance(Class<? extends T> componentType, int length) {
        return (T[]) Array.newInstance(componentType, length);
    }
}

Related

  1. newInstance(Class constructorClass, Object[] parameters)
  2. newInstance(Class klass)
  3. newInstance(Class targetClass)
  4. newInstance(Class cl, Object[] args)
  5. newInstance(Class clazz)
  6. newInstance(Class classZ)
  7. newInstance(Class clazz)
  8. newInstance(Class clazz)
  9. newInstance(Class clazz)