Class KiwiArrays2


  • public final class KiwiArrays2
    extends Object
    Utilities related to arrays.

    These utilities can be considered for inclusion into kiwi's KiwiArrays class.

    • Method Detail

      • emptyArray

        public static <T> T[] emptyArray​(Class<T> type)
        Creates an empty array of the specified type.
        Type Parameters:
        T - the type parameter representing the component type of the array
        Parameters:
        type - the class object representing the component type of the array
        Returns:
        an empty array of the specified type
        Throws:
        IllegalArgumentException - if type is null or is Void.TYPE
        See Also:
        Array.newInstance(Class, int)
        Implementation Note:
        This method exists because Array.newInstance(Class, int) returns Object and thus requires a cast. Using this method, code can be a little cleaner without a cast.
      • newArray

        public static <T> T[] newArray​(Class<T> type,
                                       int length)
        Creates a new array of the specified type and length. All values in the array are null.
        Type Parameters:
        T - the type parameter representing the component type of the array
        Parameters:
        type - the class object representing the component type of the array
        length - the length of the new array
        Returns:
        a new array of the specified type and length
        Throws:
        IllegalArgumentException - if type is null or is Void.TYPE, or length is negative
        See Also:
        Array.newInstance(Class, int)
        Implementation Note:
        This method exists because Array.newInstance(Class, int) returns Object and thus requires a cast. Using this method, code can be a little cleaner without a cast.