RFR 8015667 Stream.toArray(IntFunction) ArrayStoreException should refer to component type of array

Paul Sandoz paul.sandoz at oracle.com
Tue Dec 5 18:34:20 UTC 2017


Hi,

Since Stuart is cleaning up Collection.toArray etc we might as well do the same for Stream.toArray.

diff -r df95bd1fd4b1 src/java.base/share/classes/java/util/stream/Stream.java
--- a/src/java.base/share/classes/java/util/stream/Stream.java	Tue Dec 05 09:44:32 2017 -0800
+++ b/src/java.base/share/classes/java/util/stream/Stream.java	Tue Dec 05 10:32:27 2017 -0800
@@ -671,7 +671,8 @@
      * <p>This is a <a href="package-summary.html#StreamOps">terminal
      * operation</a>.
      *
-     * @return an array containing the elements of this stream
+     * @return an array, whose {@linkplain Class#getComponentType runtime component
+     * type} is {@code Object}, containing the elements of this stream
      */
     Object[] toArray();

@@ -694,13 +695,13 @@
      *                          .toArray(Person[]::new);
      * }</pre>
      *
-     * @param <A> the element type of the resulting array
+     * @param <A> the component type of the resulting array
      * @param generator a function which produces a new array of the desired
      *                  type and the provided length
      * @return an array containing the elements in this stream
-     * @throws ArrayStoreException if the runtime type of the array returned
-     * from the array generator is not a supertype of the runtime type of every
-     * element in this stream
+     * @throws ArrayStoreException if the runtime type of any element of this
+     *         stream is not assignable to the {@linkplain Class#getComponentType
+     *         runtime component type} of the generated array
      */
     <A> A[] toArray(IntFunction<A[]> generator);

Paul.




More information about the core-libs-dev mailing list