Is it possible to implement a Subclass, that overrides a function, which returns a Vector with specialized instances?
Example:
class ClassA{
protected _vector:Vector.<DisplayObject>;
public function get vector():Vector.<DisplayObject>{
return _vector;
}
}
class ClassB extends ClassA{
public override function get vector():Vector.<Sprite>{
return Vector.<Sprite>(_vector);
}
}
When I try to to it like this, I get an “illegal override” error at compile time.
I think that’s because the functions signatures aren’t identical.
But how can I solve this otherwise?
This is the main problem with a Vector class in ActionScript3. It basically prevents any form of polymorphism. You need to somehow remember what kind of objects your class returns. The easiest way isn’t overriding the function, but leaving it as it is and than casting each element to a appropriate form.