Feedback and comments on ARM proposal (original) (raw)
Mark Mahieu markmahieu at googlemail.com
Sat Mar 21 09:12:48 PDT 2009
- Previous message: Feedback and comments on ARM proposal
- Next message: Feedback and comments on ARM proposal
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
LOL, ok yes you could do that :) What I meant was that you couldn't write it like this:
try (Iterator elementIterator : autoRemove(elements.iterator())) { // Use elementIterator ... }
... unless of course 'Iterator' is your own Iterator type rather than the java.util version :)
Mark
2009/3/21 Tim Peierls <tim at peierls.net>
On Sat, Mar 21, 2009 at 11:30 AM, Mark Mahieu <markmahieu at googlemail.com>wrote:
For example, I couldn't get ARM to call Iterator.remove() at the end of my try blocks :)
Sure you could! You just have to really mean it. :-) public class AutoRemovingIterator extends ForwardingIterator implements AutoRemovable { private AutoRemovingIterator(Iterator it) { this.it = it; } protected Iterator delegate() { return it; } private final Iterator it; public static AutoRemovingIterator autoRemove(Iterator it) { return new AutoRemovingIterator(it); } } // In other code, with autoRemove statically imported: try (AutoRemovingIterator elementIterator : autoRemove(elements.iterator())) { // Use elementIterator ... when you're done, elementIterator.remove() will be called. } Not that this contributes anything useful to the discussion. --tim
- Previous message: Feedback and comments on ARM proposal
- Next message: Feedback and comments on ARM proposal
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]