Actionscript - make nested fixed length Vector
I want to make a nested Vector, where i define the length of the nested vector too, someting like this:
var kb:Vector.<Vector.<Number>> = new Vector.<Vector.<Number>(4)>(4); // 4x开发者_StackOverflow社区4 vector
This line throws a compilation error - anyone knows, if this is possible?
The length of a Vector
is set by a constructor argument. By using generics (type in angle brackets) you can only say that this vector is containing vectors with numbers, like this:
var outer:Vector.<Vector.<Number>> = new Vector.<Vector.<Number>>(4);
The size of nested vectors cannot be limited here since they aren't initialized. When initializing a vector which will be nested, you can do this:
var inner:Vector.<Number> = new Vector.<Number>(4);
You could also check the length of a nested vector by overriding every manipulating method of the Vector
class within a custom class where you check for the pushed vector's length.
精彩评论