If I have a superclass, say Animal,
and two subclasses: Zebra and Giraffe,
If I decide to define a Vector of Animals:
Vector <Animal> animals = new Vector();
and I want to say: You can add Giraffes, but you must own at least one Zebra first.
What is the best way to do this without using RTTI? (instanceof)
Define your own class:
Two additional points:
Personally, I would go for a design that does not use inheritance at all. So instead of subclassing vector (or ArrayList) my class will delegate to them: