commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject General API question: returning Iterator, Iterable or even Collection?
Date Mon, 03 Jun 2013 11:44:35 GMT

in compress I've added a method to ZipFile that provides access to a
subset of the entries.  It already contained a method returning an
Enumeration of all entries - Enumeration as it mimics java.util.ZipFile
which was invented in Java 1.0.

For this new method I've chosen to return an Iterator for now - there is
no reason to use Enumeration and it seemed to be closest.  In fact I
first implemented it returning Iterable and changed it later.

I've been doing quite a bit of .NET over the past years and there
IEnumerable would have been the no-brainer choice - which translates
into Iterable in Java.  Lot's of .NET APIs use IEnumerable.

My personal preference would be Iterable as well as the consumer may
iterate over the return value multiple times without copying stuff
around, but I may be missing something.

There don't seem to be many APIs in the Java classlib that consume
Iterators or Iterables at all.  That's why I bring up Collection in the

Any insights or recommendations what to return?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message