Collection.toArray(IntFunction)
Howard Lovatt
howard.lovatt at gmail.com
Thu Jun 13 05:50:09 PDT 2013
You might as well return an Object array and cast it, E[] array() { E[] array = (E[])new Object[size()]; ...; return array; }, same thing as as var ags fudge does.
Sent from my iPad
On 13/06/2013, at 3:33 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:
> 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