Type safety bug for Spliterators.spliterator

Martin Buchholz martinrb at google.com
Mon Feb 24 13:23:40 PST 2014


The following program compiles, but IMO clearly should not:

import java.util.*;
public class UncheckedSpliterator {
    public static void main(String[] args) throws Throwable {
        String[] stooges = { "Larry", "Moe", "Curly" };
        Spliterator<Integer> s = Spliterators.spliterator(stooges, 0);
    }
}

The signature of Arrays.spliterator is
public static <T> Spliterator<T> spliterator(T[] array)
while the signature of Spliterators.spliterator is
public static <T> Spliterator<T> spliterator(Object[] array,
                                                 int
additionalCharacteristics)
The second signature should take a T[] like the first,
even though the second signature happens to be convenient for collections
class implementers.
(Why are these in two separate places anyways?)


More information about the lambda-dev mailing list