> -----Original Message-----
> From: Keith Sterling [mailto:[EMAIL PROTECTED]]
>
>
> Why not create specific classes, where all the parameters are of the
> specific type. Override the constructor so that it checks the types of a
> collection it is passed
I did think of that but it's somewhat inefficient I think.
My (for-now) solution unless I find a better one is just to make sure the
'collection' is in fact of the same type;
public ExchangeRateCollection(Map t) {
super();
if (t instanceof ExchangeRateCollection) {
putAll(t);
} else {
throw new ClassCastException(eMsg);
}
}
Btw, I don't think this;
>
> public ExchangeRate set(int index, ExchangeRate element)
> {
> return (ExchangeRate )super.set(index, element);
> }
can work, because set(int index, ExchangeRate element) doesn't override
set(int index, Object element). If you do this;
ExchangeRate rate = new ExchangeRate();
String someString = "Strings are invalid collection members";
rate.set(0, someString);
Then the 'set' method of the super class is called because a String is an
Object, it's signature mightn't match the local set method but it does match
the super's. So I still have to override the set(int index, Object element)
method anyway, may as well put my class checks in there. The Collection API
says that ClassCastException is the exception to throw for type safe
collections which are given the wrong object class.
regs
scot.
To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm