Robin Rodricks
Robin Rodricks

Reputation: 114126

Create a vector with a runtime defined data type

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>();

Upvotes: 1

Views: 394

Answers (2)

ocodo
ocodo

Reputation: 30319

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

Upvotes: 5

Feltope
Feltope

Reputation: 1098

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

Upvotes: 2

Related Questions