Enumeration adapters in SE 8
Ben Evans
benjamin.john.evans at gmail.com
Wed Aug 24 14:45:03 PDT 2011
Hi Dan,
On Wed, Aug 24, 2011 at 7:10 PM, Dan Smith <daniel.smith at oracle.com> wrote:
> I was pointed to some comments on core-libs about adapting Enumerations to
> for loops in SE 8. (Sorry for the new thread -- I wasn't subscribed.) It
> turns out lambdas + extension methods will make this very easy.
>
> In the API:
>
> interface Enumeration<E> extends Iterator<E> {
> boolean hasMoreElements();
> E nextElement();
> boolean hasNext() default #hasMoreElements;
> E next() default #nextElement;
> void remove() default { throw new UnsupportedOperationException(); }
> }
>
> Note that Iterable is a function type -- a thunk producing an Iterator --
> and so we can express Iterables with lambdas and method references. It's
> becoming clear that a for loop should provide a target type for these
> things, so that will probably be part of the SE 8 feature set.
>
> With a method reference:
>
> Hashtable<String,Object> h = …;
> for (String s : h#keys) { … }
>
I'm struggling to see where this might be useful. This example is obviously
too trivial and would add nothing, but I can't see to come up with any more
extensive example where having a method reference in this position would be
actually useful.
Can someone else provide a more compelling example for a for loop taking a
method reference?
Thanks,
Ben
More information about the lambda-dev
mailing list