Re: Possible bug in JDom2

Noel Grandin <[email protected]> Mon, 19 Mar 2012 10:22:26 +0200
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
I would have thought that it should return some Collection sub-class, 
e.g. List

Since we're cleaning things up in JDOM2, now seems like a good time to 
make a change like that.

On 2012-03-15 23:59, Rolf Lear wrote:
> Hi Craig.
>
> getDescendants returns an Iterator<Element> not an Iterable<Element>
>
> Now that I think about it, it is a mess, but, that's because JDOM 1.x 
> returned an iterator.
>
> Technically your code should be:
>
> for (Iterator<Element> it =root.getDescendants(tableFilter); 
> it.hasNext(); ) {
>     tableCount++;
> }
>
> I wonder whether I can make an 'Iterable' return value too.... it 
> makes sense to, but I can't change the current return value for 
> getDescendants without breaking compatibility...
>
>
> suggestions?
>
> Rolf
>
>
>
> On 15/03/2012 3:59 PM, Craig Noah wrote:
>> I've downloaded the latest JDom2 beta today and am working to 
>> incorporate it into some new code.  I am developing against Java6, so 
>> I would expect iterators to work.  However, the following code fails 
>> to compile (with JDom2 includes):
>>
>> SAXBuilder sax = new SAXBuilder();
>> Document xml = sax.build (source);    // source is a File object
>> Element root = xml.getRootElement();
>> ElementFilter tableFilter = new ElementFilter ("Table");
>> int tableCount = 0;
>> for (Element table : root.getDescendants(
>> tableFilter)) {
>>     tableCount++;
>> }
>>
>> The compile-time error that I get states, "Can only iterate over an 
>> array or an instance of java.lang.Iterable".  Since 
>> Element.getDescendants (Filter<F>) returns a java.util.Iterator<F>, I 
>> would expect my code to compile and work.  What am I missing?
>>
>> Sincerely,
>> Craig
>>
>>
>> _______________________________________________
>> To control your jdom-interest membership:
>> http://www.jdom.org/mailman/options/jdom-interest/[email protected]
>
>
>
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/[email protected]

Disclaimer: http://www.peralex.com/disclaimer.html

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]