Feedback and comments on ARM proposal
Mark Mahieu
markmahieu at googlemail.com
Sat Mar 21 09:12:48 PDT 2009
LOL, ok yes you could do that :)
What I meant was that you couldn't write it like this:
try (Iterator<Element> 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<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