Why no return a collection when possible?

Alex Lam S.L. alexlamsl at gmail.com
Sat Aug 4 15:25:20 PDT 2012


If I am correct, a Collection can be viewed and iterator over multiple times.

Whereas an Iterable has a minimum guarantee of being able to iterate
(forward) once.


Alex.



On Sat, Aug 4, 2012 at 9:16 PM, Jose <jgetino at telefonica.net> wrote:
>
> There are many cases in which the entry point of a pilpeline is a collection
> and its size has not changed at the other end (no filters invoked).
> In this case it would be good to get a Collection. Currently I doing this by
> hand at the end of each pipeline using something like this:
>
> public static <T> Collection<T> newCollection(final Iterable<T> iterable,
> final int size) {
>      return new AbstractCollection<T>() {
>            public Iterator<T> iterator() {
>                 return iterable.iterator();
>             }
>             public int size() {
>                 return size;
>             }
>       };
> }
>
> The point is to preserve compatibility with the existing code, refractoring
> collections to Iterables would be a major task.
>
>
>
>


More information about the lambda-dev mailing list