Generic Types and Methods
- slide 5 : 21
Problems
IntSet
,
StringSet
and
ObjectSet
suffer from both programming and type problems
Problems with
IntSet
and
StringSet
Tedious to write both versions:
Copy and paste
programming.
Error prone to maintain both versions
Problems with
ObjectSet
Elements of the set must be downcasted in case we need to use some of their specialized operations
We can create an inhomogeneous set
A set of "apples" and "bananas"
Downcasting
Inhomogeneous sets can also be seen as an advantage