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;