[jdom-interest] JDom and Java5

Rolf jdom at tuis.net
Wed Feb 27 08:19:07 PST 2008


Mattias Jiderhamn wrote:
> Rolf wrote (2008-02-27 15:54):
>> Mattias Jiderhamn wrote:
>>> Rolf wrote (2008-02-27 02:55):
>>>> On the other hand, I think it would also be a *very good* solution 
>>>> to leave the method with a return type of List<?> because, as far 
>>>> as I can tell, it is fully compile-time backward-compatible with 
>>>> existing code,  ... I am sure would be far more receptive to 
>>>> migrate to 'JDom2' if the migration was 'seamless'.
>>> Does this mean you managed to compile
>>>  List<Elements> l = XPath.selectNodes(...)
>>> if XPath.selectNodes() returns List<?>; the case where I had to add 
>>> an explicit cast in comparison with the old raw "List" version to 
>>> avoid "incompatible types" error?
>>> How?
>>>
>> No, but this is what I can do...
>>
>> ...
>>
>> Now, the code following the above snippet is:
>>
>>        out.println("This WAR has "+ servlets.size() +" registered 
>> servlets:");
>>        Iterator i = servlets.iterator();
>>        while (i.hasNext()) {
>>            Element servlet = (Element) i.next();
>>            out.print("\t" + servlet.getChild("servlet-name")
>>                                    .getTextTrim() +
>>                      " for " + servlet.getChild("servlet-class")
>>                                       .getTextTrim());
>>            List initParams = servlet.getChildren("init-param");
>>            out.println(" (it has " + initParams.size() + " init 
>> params)");
>>        }
>>
>> The above construct is very typical of 'legacy' JDom and XPath usage.
>>
>> So, by returning List<?>, there are only compile-time warnings in 
>> existing legacy code, and the only difference between JDom1.1 and 
>> JDom2 is the details on the compiler warnings.
>
> Yes, but some of us have existing projects using Java5 and JDOM. In 
> some of those cases your port will - as far as I can understand - NOT 
> be "fully compile-time backward-compatible".
> I just want everybody to be fully aware of that.
>
> /Mattias
>

Hmmm. that is a new angle on it, but, for the life of me, I can't think 
of any situation where it breaks things.... How could changing the 
return type from 'List' to 'List<?>' break any code? Returning 
List<Element> would surely break things though......

... which leads me to think that some people will have issues when they 
have code that they have ported, for example, that has List<Object> kids 
= (List<Object>)element.getChildren() which would have compiled (with 
warnings) using JDom 1.1, but, will compile with errors using 'JDom2'. 
In other words, maybe JDom2 will not be a drop-in replacement for some 
people.

As for issues with List<?>, there must be something I am missing.... do 
you have an example that shows your concerns?

Rolf


More information about the jdom-interest mailing list