Albert Albert - 4 months ago 11
Java Question

Java: why does Collection.addAll can not accept Iterables?

I wonder why the

Collection.addAll()
method only accepts other
Collection
s but not
Iterable
s. Why is that?

Any similar method to do that for
Iterable
s?

Answer

Presumably because the Collection interface was introduced in Java 1.2 whereas Iterable appeared only in 1.5, and changing the interface would break all existing implementations.

Comments