Collection.toArray(IntFunction)

Zhong Yu zhong.j.yu at gmail.com
Wed Jun 12 22:33:25 PDT 2013


On Thu, May 30, 2013 at 3:14 AM, Stephen Colebourne
<scolebourne at joda.org> wrote:
> On 30 May 2013 08:30, Peter Levart <peter.levart at gmail.com> wrote:
>> String[] y = x.toArray(String[]::new);
>
> Thats very nice ;-)
> Stephen
>

Hmm...
    toArray(new String[0])
    toArray(String[]::new)
not too much difference in syntax. Try to explain it to a newbie:)

I wish we could have something like this:

   interface Collection<E>
   {
        @SafeVarargs
        E[] array(E... array);
   }

    Collection<String> x = ...;
    x.array();

This works because an empty String[] is passed in as the arg.

Zhong Yu


More information about the lambda-dev mailing list