View Full Version : BUG/ENH: BaseTreeModel generics too restrictive

29 Jun 2008, 7:42 PM
BaseTreeModel is declared as:

public class BaseTreeModel<T extends TreeModel> extends BaseModel implements TreeModel<T> { .. }

with the parent attribute of type T:

protected T parent;

and the children collection of type List<T>:

protected List<T> children;

This is extremely restrictive i.e. mandating that the parent and children be of the same type. I can honestly say that I have never actually designed or worked with tree models where all the data nodes were of the same type.

Can you split the parent and child type parameters into separate types?


29 Jun 2008, 8:09 PM
If you have different parent / child types, then specify the common super type, which may be TreeModel. In this scenario, you will need to perform the appropriate casts.