[jdom-interest] List in Element

Guillaume Pothier guillaume.pothier at inria.fr
Fri Jun 29 03:17:39 PDT 2001


Hi again !

Here is another issue related to the content and attributes members of the 
Element class. These lists can be instantiated at many places in the Element 
class (when using them first, or when performing a setContent for example).
I am writing code to allow listeners on Elements and for that purpose I use 
special kinds of lists that fire events whenever they change. Therefore it 
would be a lot easier if those lists were instantiated in a single place, for 
example :

public class Element {
//...
protected List checkContent () 
{
	if (content == null) content = new AraryList (5);
	return content;
}

protected List checkAttributes ()
{
	if (attributes == null) attributes = new ArrayList (5);
	return attributes;
}

//...
}

That would allow me to just subclass a couple of methods instead of having to 
check in the source code of Element to see where these members are 
instantiated.
I think that with the HotSpot optimizer the cost of performing the method 
call (instead of instantiating directly) should be 0.
And just another little remark : for the same purpose, the INITIAL_CAPACITY 
(or something) should be declared protected instead of private.

Yours,
Guillaume Pothier



More information about the jdom-interest mailing list