NOTE: If you try to run this against your own implementations of List, you'll need to be careful about anyplace where your RecursiveList implementation does a "new" on behalf of the code in Reversible. That is, ReversibleRecursiveList expects that each component List is also a ReversibleRecursiveList -- whereas your RecursiveList implementation most likely calls "new RecursiveList()" at some point -- probably in add. So, what this means is that you've got to worry about ensuring that you "new" an instance of the right kind of list (eg, a ReversibleRecursiveList).
There are two ways to handle this. The first is to define a protected method in RecursiveList that just does a "new RecursiveList()", and then override that method in the subtype. The second way is to define a method inside RecursiveList that creates a new instance of whatever List class it is invoked on. For example:
protected List newList() { List l = null; try { l = (List)(this.getClass().newInstance()); } catch (Exception e) { System.out.println("I am not a class instance??"); } return l; }What this does is say "for whatever kind of class "newList()" has been applied on, make a new instance -- that is, call the Constructor for the indicated list class." bershad Last modified: Sat Mar 6 18:26:27 PST 2004