多くの拡張クラスを持つ可能性のある一般的なクラスである MyCollection は、使用されているインスタンスの種類に関係なく、新しいインスタンスを作成できますか?
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;