Stream.toArray() (original) (raw)
Brian Goetz brian.goetz at oracle.com
Wed Dec 5 07:39:56 PST 2012
- Previous message: Stream.toArray()
- Next message: Stream.toArray()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Agree on the general form -- toArray(clazz) is definitely better than the current bad alternatives offered by Collection.
I prefer that the argument be the component class, not the array class. I think toArray(Foo.class) is far more natural to users than toArray(Foo[].class).
On 12/5/2012 10:33 AM, Remi Forax wrote:
Restarting a thread that ends without clear winner.
Currently, Stream.toArray() is specified as: Object[] toArray() which is not what users want, given the lack of reified generics and the fact that it's usually hard for a user to predict the number of elements of a Stream, the best signature seems to be: A[] toArray(Class arrayClass) with arrayClass.isArray() returning true and arrayClass.getComponentType().isPrimitive() returning false (or if you prefer Object[].class.isAssignableFrom(arrayClass) returning true) example of usage, Person[] coolPersons = persons.stream().filter(person#isCool()).toArray(Person[].class); cheers, Rémi
- Previous message: Stream.toArray()
- Next message: Stream.toArray()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the lambda-libs-spec-experts mailing list