Traversable vs Iterable

Boaz Nahum boaznahum at gmail.com
Tue Oct 30 03:47:09 PDT 2012


I'm just trying to understand the design guidelines

/**
 * Implementing this interface allows an object to indicate that it provides
 * the {@code forEach} method for internal iteration.
*/
public interface Traversable<T> extends Iterable<T> {


In which case we want to prevent this ability from *Iterable* ?

If we can always write:

Iterable<T> it = ...

for(T t:it) {}

Why can't we:
it.forEach(...)


Thanks
Boaz


More information about the lambda-dev mailing list