In the prerelease version of Flash Player 10 there is support for type-safe lists in the form of the new class
Vector. The class is an example of a parameterized type, meaning that you can have a vector of strings, a vector of display objects or a vector of any other type you like. Parameterized types are called “genetics” in Java and “templates” in C++ and it’s a really nice feature to have.
Unfortunately it seems like you can’t write your own parameterized types,
Vector is what you get. Hopefully this is the first sign of things to come, perhaps there will be more in the next version of the player. Watch this space.
Just to check I’ve also tried some other ECMAScript 4 features like
type and generic functions, but none seems supported.
Update: Seems like the parameterized types doesn’t work very well with
shift and other array manipulation methods, they accept any type, even though they shouldn’t (likely because are implemented using variable argument lists, which is one of the cases where ActionScript’s typing system breaks down). Also, it breaks down for nested types like
var list : Vector.<Vector.<String>> (which allows any vector type to be assigned to the vector, which it shouldn’t. This line should not compile
list = new Vector.<int>(), but it does).