[jdom-interest] detach() [eg]

Joseph Bowbeer jozart at csi.com
Sun Apr 22 21:35:34 PDT 2001


I agree that if Elliotte's proposal (throwing an exception) is a good way to
*not* allow someone to detach a root element.

Also, I suggest the following idiom for users who want to get around this
restriction without having to catch the exception:

    if (!elt.isRootElement()) { // precondition for detach
        elt.detach();
    } else {
        elt.getDocument().setRootElement(new Element("foo"));
    }

An advantage of Elliotte's proposal over an implicit "placeholder" is that
we're leaving the door open for a future enhancement that *would* allow
someone to detach the root element :-)

--
Joe Bowbeer







More information about the jdom-interest mailing list