Avoiding RTTI In Java
        Posted  
        
            by destructo_gold
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by destructo_gold
        
        
        
        Published on 2010-03-26T06:29:14Z
        Indexed on 
            2010/03/26
            6:33 UTC
        
        
        Read the original article
        Hit count: 561
        
Hi,
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)
© Stack Overflow or respective owner