[jdom-interest] JDom and Java5
Mattias Jiderhamn
mj-lists at expertsystems.se
Wed Feb 27 07:45:32 PST 2008
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
More information about the jdom-interest
mailing list