[jdom-interest] insertChild in Element
jhunter at collab.net
Fri Sep 1 19:59:40 PDT 2000
> In the "do what you like" category - unfortunately - is that you can add any
> arbitrary object. We lose type safety by exposing a live List to the programmer
> due to the non-type-safe containers :-( This is a very large blow to
> "good programming principles", IMO.
It's something that would be nice to avoid but it's endemic to the
language. It's common in Java to use a List that (although the API
accepts Object) really only takes some special class or set of classes.
> Personally, I would not expose the List for this reason alone because the
> compiler can no longer catch simple errors.
Raise your hand if you've added an object as a child of Element that
can't legally be a child of Element. I doubt we'll see many hands.
:-) I agree we should check so you get a nice runtime error if you do
make the mistake, but is this really so likely to occur it's worth
adding a hunk of methods (and making lists immutable and changing the
core design of JDOM) so you get a compile time error? I think not.
You could argue that JDOM should have immutable lists and that Element
should have every method that would change its child content and
attributes (dozens), but early on we favored delegating list management
to the Java-standard collections APIs, for various reasons like reducing
the size of the API, leveraging standard APIs, reducing the required
implementation code, and so on.
More information about the jdom-interest