Why does the characteristics method return enum for Collector, but int for Spliterator?

In Java 8, both collectors and delimiters, although not directly related, have a method characteristics()

that appears to serve the same general purpose.

Why does the method characteristics()

in Collector return enum

, but in Spliterator it returns int

(possibly C-style enum

)? They don't seem to be consistent.

+3


source to share


1 answer


The utility class Collectors

contains several static, pre-allocated, unmodifiable sets of various collector characteristics that are required for those supplied by the JDK. There are only a few possible combinations of collector flags, so it's pretty easy to do this.

On the other hand, there are many spliterator sources out there. Coding the many possible combinations of characteristics in sets could be considered too costly. Especially if some developers can select them on the fly.



They are also heavily modified, added or removed characteristics as the flow pipeline is built, which can be achieved cheaply with binary arithmetic.

Flags

int is just cheaper.

+1


source







All Articles