Can MyCollection, which is a general class which may have many extending classes, create a new instance of whatever kind of instance is being used?
public class MyCollection extends Array {
public function getUnionWith(someCollection:MyCollection):MyCollection {
//can I create and return a new instance of the same class as this instance here?
//(so in this example: a new ViewCollection or ItemCollection)
}
}
public class ItemCollection extends MyCollection { }
public class ViewCollection extends MyCollection { }
...
//so that this will work:
var viewsOccuringInBoth:ViewCollection = viewCollection1.getUnionWith(viewCollection2) as ViewCollection;
//but this will work too!
var itemsOccuringInBoth:ItemCollection = itemCollection1.getUnionWith(itemCollection2) as ItemCollection;
I think similar to described here could be used in your getUnionWith method: