title: Passing Vector.<T> references as Object, casting causes a copy to be made
body: <p>I'd like to be able to pass <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Vector.html" rel="nofollow">Vectors</a> around <em>as references</em>.  Now, if a method takes a <code>Vector.&lt;Object&gt;</code>, then passing a <code>Vector.&lt;TRecord&gt;</code>, where TRecord inherits directly from Object does not work.  Where a method takes just plain <em>Object</em>; say <code>vec: Object</code>, then passing the Vector is possible.  Once inside this method, an explicit cast at some stage is required to access <code>vec</code> as a Vector again.  Unfortunately, a cast seems to make a copy, which means wrapping one up in multiple Flex ListCollectionViews is useless; each ListCollectionView will be pointing to a different Vector.</p>
  
  <p>Using Arrays with ArrayCollection presents no such problem, but I lose out out the type safety, neatness (code should be clean enough to eat off of) and performance advantages of Vector.</p>
  
  <p>Is there a way to cast them or pass them as references in a generic manner without copies being made along the way?</p>
  
  <p>Note in this example, IRecord is an interface with {r/w id: int &amp; name: String} properties, but it could be a class, say TRecord { id: int; name: String} or any other usable type.</p>
  
  <pre><code>protected function check(srcVec: Object): void
  {
    if (!srcVec) {
      trace("srcVec is null!");
      return;
    }
    // srcVec = (@b347e21)
    trace(srcVec.length); // 4, as expected
    var refVec: Vector.&lt;Object&gt; = Vector.&lt;Object&gt;(srcVec);
    // refVec = (@bc781f1)
    trace(refVec.length); // 4, ok, but refVec has a different address than srcVec
    refVec.pop();
    trace(refVec.length); // 3 ok
    trace(srcVec.length); // 4 - A copy was clearly created!!!
  }
  
  protected function test(): void
  {
    var vt1: Vector.&lt;IRecord&gt; = new Vector.&lt;IRecord&gt;;  // (@b347e21) - original Vector address
    var vt2: Vector.&lt;Object&gt; = Vector.&lt;Object&gt;(vt1);   // (@bbb57c1) - wrong
    var vt3: Vector.&lt;Object&gt; = vt1 as Vector.&lt;Object&gt;; // (@null)    - failure to cast
    var vt4: Object = vt1;                             // (@b347e21) - good
    for (var ix: int = 0; ix &lt; 4; ix++)
      vt1.push(new TRecord);
    if (vt1) trace(vt1.length); // 4, as expected
    if (vt2) trace(vt2.length); // 0
    if (vt3) trace(vt3.length); // vt3 is null
    if (vt4) trace(vt4.length); // 4
    if (vt1) trace(Vector.&lt;Object&gt;(vt1).length); // 
    trace("calling check(vt1)");
    check(vt1);
  }
  </code></pre>