0
MyCollection是一個可以有多個擴展類的通用類,它是否可以創建一個正在使用的實例的新實例?AS3 - 基類可以創建與自己的實例相同的擴展類的新實例嗎?
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;
如若ItemCollection和ViewCollectio延長MyCollection的? 新的MyCollection將是MyCollection。您需要重新解釋問題或提供更多的上下文。 –
每個祖先類應該實現它自己的版本的getUnionWith方法:) –