2 Replies Latest reply on May 5, 2010 12:27 PM by -BoNzO-

    Vector does not like polymorphism ?

    -BoNzO- Level 2



      It seems like only concrete types can be used for vector types, not interfaces or abstract classes.


      All those examples won't work :


      private var vector : Vector.<UIComponent>;

      private function doSomething( input : Vector.<IUIComponent> ) : void

      doSomething( vector );

      private var vector : Vector.<Sprite>;

      private function doSomething( input : Vector.<DisplayObject> ) : void

      doSomething( vector );


      private var vector : Vector.<EventDispatcher>;

      private function doSomething( input : Vector.<Object> ) : void

      doSomething( vector );



      Is there a way to achieve this ? Or maybe I can know the reason the implementation forbids it ? I know vectors are optimized for a particular type but it would be so much nicer if more flexibility was also possible. For instance, a lot of logic can't be reused for different vectors since developers have to code against an unique type.