[jdom-interest] Java 5.0 JDOM Plans?

Bradley S. Huffman hip at a.cs.okstate.edu
Tue Aug 30 21:37:49 PDT 2005


Jason Hunter writes:

> >>detach() is a big annoying one.
> > 
> > Don't see that one?
> 
> Content has a detach() that returns type Content, which means you can't 
> anymore say:
> 
> Element detached = otherElt.detach();
> 
> You have to cast:
> 
> Element detached = (Element) otherElt.detach();

But you already know otherElt *is* a Element since detach returns the node it's
called on. And you can avoid the cast with

    otherElt.detach();
    Element detached = otherElt;

In this use case, I don't see a benefit.

> With Java 5, the call to detach() could return Element specifically.  A 
> docType.getParent() could return Document instead of Parent.  A 
> text.getParent() likewise could return Element.

I see the use with getParent(), it's the other methods I'm having problems
with. What about getContent(int), which is the bases for all the other
getContent methods, can covariant returns help there and how?

> Covariant return types let you return specific types rather than 
> superclass types, and it's nice because beginners don't even realize 
> there's this fancy thing going on -- it just makes sense.

Doesn't make sense to me. So far I see only one method that might benefit
from this feature. Give me use cases :-)

Brad


More information about the jdom-interest mailing list