Feedback and comments on ARM proposal

Tim Peierls tim at peierls.net
Sat Mar 21 09:07:58 PDT 2009


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<T> extends ForwardingIterator<T>
implements AutoRemovable {
    private AutoRemovingIterator(Iterator<T> it) { this.it = it; }
    protected Iterator<T> delegate() { return it; }
    private final Iterator<T> it;

    public static AutoRemovingIterator<T> autoRemove(Iterator<T> it) {
        return new AutoRemovingIterator<T>(it);
    }
}

// In other code, with autoRemove statically imported:

    try (AutoRemovingIterator<Element> 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



More information about the coin-dev mailing list