Collection.toArray(IntFunction)
Remi Forax
forax at univ-mlv.fr
Thu Jun 13 00:09:23 PDT 2013
On 06/13/2013 07:33 AM, Zhong Yu 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:)
Apart from the coloncolon syntax (::), it's easy either you give the
size or not.
>
> 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.
Without discussing about the restrictions on @SafeVarargs, It depends
what you mean by it works, if it's apart creating a big hole in the type
safety of all programs because this method allows to create arrays of
parametrized types which are unsafe, I agree with you, it works :)
>
> Zhong Yu
>
Rémi
More information about the lambda-dev
mailing list