Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] adding an iterator() method to nodes

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Ed Davies <edavies AT nildram.co.uk>
  • To: Steve Loughran <steve.loughran AT gmail.com>, xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] adding an iterator() method to nodes
  • Date: Tue, 31 Oct 2006 15:43:51 +0000

Steve Loughran wrote:
... I make my iterators implement iterable instead:
public Iterator<Node> iterator() {
return this;
}
...

Clever way to save garbage collection of a separate Iterable
object, but shouldn't an Iterable return a new Iterator each
time iterator() is called?

I realise that's not likely to happen in your common usage
pattern but, still, wouldn't it be safer to at least throw an
exception if iterator() is called twice? That wouldn't guard
against a direct cast from Iterable to Iterator, of course,
but that would be cheating.

Ed.




Archive powered by MHonArc 2.6.24.

Top of Page