Generics

Daniel Altman daniel at qkss.com
Fri Oct 3 13:14:22 UTC 2003


Hi Phil !

> A Collection can hold zero or more elements, each of any type. Sometimes
> you nevertheless need to ensure that all elements are of the same type.
> Say you're collecting Integers and by accident you insert a Symbol
> representing an integer value, say #'3'. Your code assumes that every
> element of your collection will respond to #even; therefor, it errors
> when it iterates over the Symbol element. You can choose to trap this
> *particular* error in this *particular* case, or you can (should be able
> to) choose to use a Collection that takes care of ensuring this *general
> case* of error *cannot* occur.

What does "a Collection that takes care of ensuring this *general case* of
error *cannot* occur" means for you?
What will the collection do when someone try to insert an element of the
wrong type on it?

I mean, lets suppose the collection can detect that the object that is being
added to it is of the wrong type (whatever meaning you give to "type" here).
What is it expected to do? It could raise an Exception...but the program
will break anyway! Does it make sense to introduce those "type checking" at
runtime? I don't think so...



======================================
Daniel Altman
Buenos Aires, Argentina





More information about the Squeak-dev mailing list