Hi guys, really going at it on a Saturday, eh?
On 5/16/15 3:46 PM, Claes Redestad wrote:
I also realized Iterable should typically allow multiple passes over the
collection/enumeration, so this wouldn't feel right. Sorry!
So... I'm happy with Stuart's proposal.
Yep, that's the main reason not to have Enumeration extend Iterable. Although it
isn't written down explicitly, common usage expects that each call to iterator()
produce a fresh instance, positioned at the beginning, independent of other
instances.
I would also be happy (happier?) with a stream variant:
pc.elements().stream().forEach(this::doSomethingWithPermission);
I think Rémi answered this well.
and remember, prefer composition to inheritance :)
*ducks* :)
Yep. While we're at it, though, the "obvious" alternative is to have Enumeration
extend Iterator (as opposed to Iterable). This could work, but it has a fairly
big risk of incompatibility. Iterator<T> defines a next() method returning T,
and it seems pretty likely that there's code out there that has a next() method.
If it returned T, it wouldn't be an error, but the resulting Iterator probably
wouldn't function properly. If it returned something other than T, it'd be a big
source incompatibility.
Of course, in principle, the same thing could occur with "asIterator". But that
seems much less likely to collide with something than "next".
s'marks
/Claes
/Claes
Rémi
On 2015-05-16 02:37, Stuart Marks wrote:
Hi all,
Please review this small API enhancement to add a default method
"asIterator()" to Enumeration that converts it into an Iterator.
Webrev:
http://cr.openjdk.java.net/~smarks/reviews/8072726/webrev.0/
Bug:
https://bugs.openjdk.java.net/browse/JDK-8072726
Thanks,
s'marks