diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java index f4dd64082..c27e71c3e 100644 --- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java +++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java @@ -265,39 +265,40 @@ public class ArrayUtils { // Generic array //----------------------------------------------------------------------- /** - * Create a type-safe generic array. + *

Create a type-safe generic array.

* - *

Arrays are covariant i.e. they cannot be created from a generic type:

+ *

The Java language does not allow an array to be created from a generic type:

* *
     public static <T> T[] createAnArray(int size) {
-        return T[size]; // compiler error here
+        return new T[size]; // compiler error here
     }
     public static <T> T[] createAnArray(int size) {
         return (T[])new Object[size]; // ClassCastException at runtime
     }
      * 
* - *

Therefore new arrays of generic types can be created with this method, e.g. an arrays - * of Strings:

+ *

Therefore new arrays of generic types can be created with this method. + * For example, an array of Strings can be created:

* *
     String[] array = ArrayUtils.toArray("1", "2");
     String[] emptyArray = ArrayUtils.<String>toArray();
      * 
* - * The method is typically used in scenarios, where the caller itself uses generic types - * that have to be combined into an array. + *

The method is typically used in scenarios, where the caller itself uses generic types + * that have to be combined into an array.

* - * Note, this method makes only sense to provide arguments of the same type so that the + *

Note, this method makes only sense to provide arguments of the same type so that the * compiler can deduce the type of the array itself. While it is possible to select the - * type explicitly like in Number[] array = ArrayUtils.<Number>toArray(new - * Integer(42), new Double(Math.PI)), there is no real advantage to new - * Number[] {new Integer(42), new Double(Math.PI)} anymore. + * type explicitly like in + * Number[] array = ArrayUtils.<Number>toArray(new Integer(42), new Double(Math.PI)), + * there is no real advantage when compared to + * new Number[] {new Integer(42), new Double(Math.PI)}.

* * @param the array's element type - * @param items the items of the array - * @return the array + * @param items the varargs array items, null allowed + * @return the array, not null unless a null array is passed in * @since 3.0 */ public static T[] toArray(final T... items) {