Create a vector with a runtime defined data type

415 Views Asked by At

Typically you create a Vector (strongly typed array) specifying a data type like:

new Vector<PictureBox>();

However I need to create a utility method that should be able to create a vector of any given datatype. Is it possible to specify a type using a variable instead of hard-coding it?

var type:Class = PictureBox;
new Vector<type>();
2

There are 2 best solutions below

4
On BEST ANSWER

You cannot do it exactly the way you want, but you could use a set of classes which implement the same interface, and then type your vector with that interface, e.g.:

var list:Vector.<IBox>

class PictureBox implements IBox
class TextBox implements IBox
0
On

I am sure Vector<> has to be strongly typed.