var spriteList:Vector. = new Vector.()
var genericList:Vector.
应该使用全局Vector()函数/ cast来执行赋值,如下所示:
var spriteList:Vector. = new Vector.()
var genericList:Vector. = new Vector.()
genericList = Vector.(spriteList)
这是一个简单的例子,我没有阅读文档.
下面是一些测试代码,我期待Vector.隐式转换为Vector.<*>.
public class VectorTest extends Sprite
{
public function VectorTest()
{
// works, due to <*> being strictly the same type as the collection in VectorContainer
var collection:Vector.<*> = new Vector.()
// compiler complains about implicit conversion of to <*>
var collection:Vector. = new Vector.()
collection.push("One")
collection.push("Two")
collection.push("Three")
for each (var eachNumber:String in collection)
{
trace("eachNumber: " + eachNumber)
}
var vectorContainer:VectorContainer = new VectorContainer(collection)
while(vectorContainer.hasNext())
{
trace(vectorContainer.next)
}
}
}
public class VectorContainer
{
private var _collection:Vector.<*>
private var _index:int = 0
public function VectorContainer(collection:Vector.<*>)
{
_collection = collection
}
public function hasNext():Boolean
{
return _index < _collection.length
}
public function get next():*
{
return _collection[_index++]
}
}