[jdom-interest] JDom and Java5
Victor Toni
victor.toni at ebuconnect.de
Wed Feb 27 09:23:42 PST 2008
Mattias Jiderhamn wrote:
> Rolf wrote (2008-02-27 17:19):
>> 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......
>
> See the (real life) example I have provided
> List<Elements> l = XPath.selectNodes(...)
> gives a compiler warning with the current JDOM release, but does not
> compile against your code.
>
> If we want a drop in replacement, I believe we will have to stick with
> raw "List" for selectNodes().
>
> (It may also be worth noting that the main, or at least first, users
> of JDOM with Java5 are probably those already on Java5 projects using
> JDOM).
One could still use the mentioned "<T> List<T>" approach. This should
work for old and new code without needing an explicit cast...
More information about the jdom-interest
mailing list