Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 28662 invoked from network); 4 Mar 2011 12:42:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Mar 2011 12:42:16 -0000 Received: (qmail 49628 invoked by uid 500); 4 Mar 2011 12:42:16 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 49584 invoked by uid 500); 4 Mar 2011 12:42:16 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 49577 invoked by uid 99); 4 Mar 2011 12:42:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Mar 2011 12:42:16 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Mar 2011 12:42:09 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5F8A123889E7; Fri, 4 Mar 2011 12:41:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1077915 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java Date: Fri, 04 Mar 2011 12:41:48 -0000 To: commits@commons.apache.org From: scolebourne@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110304124148.5F8A123889E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: scolebourne Date: Fri Mar 4 12:41:48 2011 New Revision: 1077915 URL: http://svn.apache.org/viewvc?rev=1077915&view=rev Log: Javadoc ArrayUtils.toArray() Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java?rev=1077915&r1=1077914&r2=1077915&view=diff ============================================================================== --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java (original) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java Fri Mar 4 12:41:48 2011 @@ -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) {