Introduction to OOP | Chapter 19: Container Classes : | next | previous | audio | real | text |
Therefore, we write containers that store Object values.
Problem. Requires a cast when a value is removed from the container.
Vector aVector = new Vector(); Cat Felice = new Cat(); aVector.addElement(Felice); ... // cast used to convert Object value to Cat Cat animal = (Cat) aVector.elementAt(0);Worse problem, typing errors are detected when a value is removed from the collection, not when it is inserted.