Dan R
Dan R

Reputation: 1494

Why doesn't IntStream.spliterator() return Spliterator.OfInt since Java 11?

In Java 8, IntStream.spliterator() is overridden from the base class to return type Spliterator.OfInt, which is a sub-interface providing methods that operate on an IntConsumer instead of a generic Consumer<Integer>.

But since Java 11 (and continuing with 17 and 20), IntStream inherits the base class spliterator() method which only returns a generic Spliterator<Integer>.

I believe the reason for these specialized primitive types is largely to avoid the expensive overhead of constant boxing and unboxing (see for example this SO answer). If so, then there is a performance hit for using Spliterator<Integer> rather than Spliterator.OfInt. Does anyone know why this specialization in IntStream was removed?

Upvotes: 3

Views: 116

Answers (0)

Related Questions