ch.javasoft.lang.reflect
Class Array

java.lang.Object
  extended by ch.javasoft.lang.reflect.Array

public class Array
extends Object

The Array class contains static methods to instantiate arrays for generic types.


Method Summary
static
<T> T[]
newInstance(Class<T> componentType, int length)
          Creates a new array of the given component type.
static
<T> T[][]
newInstance(Class<T> componentType, int rows, int cols)
          Creates a new array of the given component type.
static
<T> T[]
newInstanceInstantiate(Class<T> componentType, int length)
          Creates a new array of the given component type, and initializes the array with new instances by calling the default constructor of componentType
static
<T> T[][]
newInstanceInstantiate(Class<T> componentType, int rows, int cols)
          Creates a new array of the given component type, and initializes the array with new instances by calling the default constructor of componentType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static final <T> T[] newInstance(Class<T> componentType,
                                        int length)
Creates a new array of the given component type. The new array contains null values

Type Parameters:
T - the component type generic parameter
Parameters:
componentType - the component type class
length - the length of the new array
Returns:
the array

newInstance

public static final <T> T[][] newInstance(Class<T> componentType,
                                          int rows,
                                          int cols)
Creates a new array of the given component type. The new array contains null values

Type Parameters:
T - the component type generic parameter
Parameters:
componentType - the component type class
rows - the length of the first dimension of the new array
cols - the length of the second dimension of the new array
Returns:
the array

newInstanceInstantiate

public static final <T> T[] newInstanceInstantiate(Class<T> componentType,
                                                   int length)
                                        throws InstantiationException,
                                               IllegalAccessException
Creates a new array of the given component type, and initializes the array with new instances by calling the default constructor of componentType

Type Parameters:
T - the component type generic parameter
Parameters:
componentType - the component type class
length - the length of the new array
Returns:
the array with new instances
Throws:
InstantiationException - if calling the default constructor fails
IllegalAccessException - if calling the default constructor fails

newInstanceInstantiate

public static final <T> T[][] newInstanceInstantiate(Class<T> componentType,
                                                     int rows,
                                                     int cols)
                                          throws InstantiationException,
                                                 IllegalAccessException
Creates a new array of the given component type, and initializes the array with new instances by calling the default constructor of componentType

Type Parameters:
T - the component type generic parameter
Parameters:
componentType - the component type class
rows - the length of the first dimension of the new array
cols - the length of the second dimension of the new array
Returns:
the array with new instances
Throws:
InstantiationException - if calling the default constructor fails
IllegalAccessException - if calling the default constructor fails