Could anyone pls point me to good discussions on implementing type-safe
collections. I'm pretty familar with the Collections API and I have got +
read the Zukowski book, Java Collections, which is excellent (I recommend
this heartily if you are still stuck in using Vectors, Stacks, Hashtables,
Enumerations or worse). I'd like to get some good hard info on extending the
collections classes or implementing the interfaces to make collections which
are type safe.
By type safe I mean making sure all elements of a particular collection are
of type T. Currently I have done it by extending a collection
implementation such as ArrayList and overriding certain methods;
/**
* @see java.util.List#set(int, Object)
*/
public Object set(int index, Object element) {
if (element instanceof ExchangeRate) {
return super.set(index, element);
} else {
throw new ClassCastException(eMsg);
}
}
However I'm not sure what to do with the constructors that take a collection
interface as the argument. Currently they throw
OperationNotSupportedException.
Also I just want to sanity check what I'm doing. Any tips or pointers
appreciated!
regs
scot.
___________________________________________
Scot Mcphee - Snr Developer
- (mobile) +61-412-957414
___________________________________________
Tigerex - http://www.tigerex.net
- (bus) +61-2-82593613
___________________________________________
To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm