Unfortunately ActionScript 3 does not have a concept of generics, so it follows that there is no way to define a typed array as
Array<T>. There is however a special class
Vector.<T> which works in a similar way except you must provide a reference to a concrete class when instantiating the vector. This means there is no way to build abstractions on top of the
Vector.<T> type (e.g. extend it and add new functionality) which is a huge drawback.
A simpler way to look at is is as though every class you define automatically had a companion class named
With that said, there are still huge advantages to the
Vector.<T> type over a conventional array:
TypeErrors if you attempt to insert non-T values into the collection.
Examples of creating a
var strings:Vector.<String> = new Vector.<String>(); // or var numbers:Vector.<Number> = new <Number>;
1 Vectors actually only provide notable performance improvements over arrays when working with primitive types (