Question

With C# I grew to love the IEnumerable<T> interface. There are a lot of cases where that's all you want to give out and take in. In addition it's useful in the .Net library. You have for example a constructor on the List<T> class which takes an IEnumerable<T>.

I have to work with Java at the moment, and I naturally wanted to use the equivalent Iterable<T> interface. However, it doesn't really seem like I can use it anywhere. Everything seems to be using the extended Collection<T> interface instead. Why is this?

As an example, you have the ArrayList<T> constructor which takes a Collection<T>:

Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Why not just take an Iterable<T> instead?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top