Type safety bug for Spliterators.spliterator

Ali Ebrahimi ali.ebrahimi1781 at gmail.com
Mon Feb 24 22:28:21 PST 2014


Hi,

On Tue, Feb 25, 2014 at 6:21 AM, Martin Buchholz <martinrb at google.com>wrote:

> On Mon, Feb 24, 2014 at 4:38 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:
>
> > T[] to Spliterator<T> is not general enough, we'll need T[] to
> > Spliterator<S> where S is a subtype of T. Caller guarantees that the
> > T[] array contains only S elements.
> >
> > So we might want something like
> >
> >     <T, S extends T> Spliterator<S> spliterator(T[] array, int)
> >
>
> Don't you want S super T instead?
>
This is not valid in java.


This is my suggestion:

<T, S extends Spliterator<? extends T>> S spliterator(T[] array, int g)


        Number[] nums= { 1, 1.0, 1 };
        Spliterator<Number> sn = spliterator(nums, 0); //ok
        Spliterator<Integer> si = spliterator(nums, 0);//ok
        Spliterator<Double> sd = spliterator(nums, 0);//ok
        Spliterator<String> ss = spliterator(nums, 0);//compile error
        Spliterator<Object> so = spliterator(nums, 0);//compile error


Regards,
Ali Ebrahimi


More information about the lambda-dev mailing list