Wednesday, May 23, 2012

ActionScript Vector casting inconsistency?

When a Vector is casted like this...

var v1:Vector.<String> = new Vector.<String>();

var v2:Vector.<Object> = Vector.<Object>(v1)


trace(v1); //foo,bar
trace(v2); //foo

... a copy of the Vector is created, as you can see in the trace output.

But when you change line 3 to...

var v2:Vector.<*> = Vector.<*>(v1)

... no copy is created, both v1 and v2 point to the same object, trace outputs will both be "foo,bar".

Why that? Shouldn't there somehow be a consistent behaviour?

No comments:

Post a Comment