तो यह जवाब की तरह लग रहा है पर कोई रास्ता नहीं करने के लिए परोक्ष वैध सुपर प्रकार करने के लिए एक प्रकार का एक वेक्टर डाली है। यह वैश्विक वेक्टर के साथ स्पष्ट रूप से किया जाना चाहिए। <> फ़ंक्शन।
तो मेरी वास्तविक समस्या समस्याओं का मिश्रण :)
यह वेक्टर उपयोग करने के लिए सही है था। एक और वेक्टर के लिए एक सामान्य संदर्भ, लेकिन जैसा कि यह इस प्रकार नहीं किया जा सकता:
var spriteList:Vector.<Sprite> = new Vector.<Sprite>()
var genericList:Vector.<Object> = new Vector.<Object>()
genericList = spriteList // this will cause a type casting error
काम वैश्विक वेक्टर() फ़ंक्शन/तो जैसे डाली का उपयोग किया जाना चाहिए:
var spriteList:Vector.<Sprite> = new Vector.<Sprite>()
var genericList:Vector.<Object> = new Vector.<Object>()
genericList = Vector.<Object>(spriteList)
यह था मेरे पास एक साधारण मामला documentation नहीं पढ़ रहा है।
नीचे कुछ परीक्षण कोड है, मैं वेक्टर की अपेक्षा करता हूं। वेक्टर को निहित रूप से डालने के लिए। < *>।
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.<String>()
// compiler complains about implicit conversion of <String> to <*>
var collection:Vector.<String> = new Vector.<String>()
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++]
}
}
स्रोत
2009-03-01 10:35:50
यह एक अच्छा सवाल है। अज्ञात क्षेत्र! – Iain