Java Class New Instance newInstance(Class arrayComponentClass, T value)

Here you can find the source of newInstance(Class arrayComponentClass, T value)

Description

Create single element array of the specified class which contains the specified value

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
public static <T> T[] newInstance(Class<T> arrayComponentClass, T value) 

Method Source Code


//package com.java2s;
// This package is part of the Spiralcraft project and is licensed under

import java.lang.reflect.Array;

public class Main {
    /**/*from  www.j av  a  2  s .c  o  m*/
     * Create single element array of the specified class which contains the
     *   specified value
     */
    @SuppressWarnings("unchecked")
    public static <T> T[] newInstance(Class<T> arrayComponentClass, T value) {
        T[] array = (T[]) Array.newInstance(arrayComponentClass, 1);
        array[0] = value;
        //    Array.set(array,0,value);
        return array;
    }
}

Related

  1. newInstance(Class componentType, int... dimensions)
  2. newInstance(Class entity)
  3. newInstance(Class theClass, Class expected)
  4. newInstance(Class interfaceDefinition, String className, ClassLoader classLoader)
  5. newInstance(Class aClass, Object... args)
  6. newInstance(Class beanClass)
  7. newInstance(Class c)
  8. newInstance(Class c)
  9. newInstance(Class c, Class[] argTypes, Object[] args)