Re: foreach and stack, iterating from the bottom-up?
- From: Andreas Leitgeb <avl@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: 06 May 2008 13:41:00 GMT
Lew <lew@xxxxxxxxxxxxx> wrote:
Andreas Leitgeb wrote:
the descendingIterator() is another argument in favour of
allowing for-loops with iterators, not just iterables.
For loops are allowed with iterators. The enhanced for loop is syntactic
sugar designed for one common use, only.
Technically 100% correct.
It's just the fact behind the "only" which I'm ranting about.
Just do:
for ( Iterator <Foo> iter = deq.descendingIterator(); iter.hasNext(); )
{ Foo foo = iter.next();
Ok, it's about equally ugly, than mine, but I admit it's more efficient.
This is the idiom, for which to avoid the syntactic sugar was added.
Even more such idioms could have easily been sugar-coated as well, but
were left out, back then in the days of 1.5, probably because those
descending iterators were only "invented" later (with 1.6) for Java.
The whole concept of the Iterable interface has one sore point, that
it cannot deal with a pluralism of ways to iterate something.
It's the same "problem" for which Comparator's exist besides
the Comparable interface, except of course, that this thread
is only about sugar coating, not about new functionality.
Extending the syntactic sugar to not be crippled by that limitation
of Iterable, would be a "good thing", imo. However, I admit that it
is *not* a necessity, as it may have looked like from my previous posting.
PS: My sample was already much smaller than the one I followed up to.
.
- References:
- foreach and stack, iterating from the bottom-up?
- From: WP
- Re: foreach and stack, iterating from the bottom-up?
- From: Piotr Kobzda
- Re: foreach and stack, iterating from the bottom-up?
- From: Andreas Leitgeb
- Re: foreach and stack, iterating from the bottom-up?
- From: Lew
- foreach and stack, iterating from the bottom-up?
- Prev by Date: Re: SCJP 1.5 exam
- Next by Date: It's now or never。shopping in our company to get beijing2008 keepsake
- Previous by thread: Re: foreach and stack, iterating from the bottom-up?
- Next by thread: Re: foreach and stack, iterating from the bottom-up?
- Index(es):
Relevant Pages
|