foreach - What are the Advantages of Enhanced for loop and Iterator in Java? -
can please specify me advantages of enhanced loop , iterators in java +5 ?
the strengths , weaknesses pretty summarized in stephen colebourne (joda-time, jsr-310, etc) enhanced each loop iteration control proposal extend in java 7:
feature summary:
extends java 5 for-each loop allow access loop index, whether first or last iteration, , remove current item.
major advantage
the for-each loop new popular feature java 5. it works because increases abstraction level - instead of having express low-level details of how loop around list or array (with index or iterator), developer states want loop , language takes care of rest. however, benefit lost developer needs access index or remove item.
the original java 5 each work took relatively conservative stance on number of issues aiming tackle 80% case. however, loops such common form in coding remaining 20% not tackled represents significant body of code.
the process of converting loop each index or iterator based painful. because the old loop style if lower-level, is more verbose , less clear. painful ides don't support kind of 'de-refactoring'.
major benefit:
a common coding idiom expressed @ higher abstraction @ present. aids readability , clarity.
...
to sum up, enhanced loop offers concise higher level syntax loop on list or array improves clarity , readability. however, misses parts: allowing access index loop or remove item.
Comments
Post a Comment