Why did new Spliterators
class appear in Java 8? Since Java 8 we have possibility to add static
methods to the interfaces.
Since Spliterators
class has only static method wouldn't be simpler to declare all its methods in the Spliterator
interface
?
The same question about Collectors/Collector
pair.
Thank you.
It’s perfectly possible that this decision was made without even thinking about this brand new possibility, but simply following the established-since-twenty-years pattern.
Besides that, it can be debated whether it is really useful to add 25 to 30 static
methods to an interface. It makes sense to offer a few factories for canonical implementations, but you should draw a line somewhere. It’s not feasible to add factories to all implementations to an interface, just because they are offered by the same library. But this debate would be off-topic.
Further, Spliterators
does not only offer static
methods, but also nested classes. Unlike static
methods, these classes would pollute the name space of every implementation class, when being defined in an interface
.
Collectors
and Spliterators
may also contain implementation-specific non-public
methods and even fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With