Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7978659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:32:58+00:00 2026-06-04T09:32:58+00:00

When a Vector is casted like this… var v1:Vector.<String> = new Vector.<String>(); v1.push(foo); var

  • 0

When a Vector is casted like this…

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

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

v1.push("bar");

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:32:59+00:00Added an answer on June 4, 2026 at 9:32 am

    What you have to realize is that Vector.<Something>(Vector.<Anotherthing>) is not a type cast. In fact, you can’t cast a vector of one kind to a vector of another kind at all! Try this:

    var v1:Vector.<String> = new Vector.<String>();
    var v2:Vector.<Object> = v1 as Vector.<Object>; // throws an error
    

    You also can’t assign a vector of subtypes:

    var v1:Vector.<Object> = new Vector.<String>(); // throws an error
    

    That is because while String is a subtype of Object, the two kinds of vectors are not related.

    So why doesn’t your notation fail? Because what you are really doing is calling the top level function Vector(), which creates a vector from any collection type data you pass in. The documentation for it says:

    If the sourceArray argument is already a Vector.<T> instance where T is the base type, the function returns that Vector. Otherwise, the result Vector is populated with the elements of the sourceArray Array or Vector.

    The asterisk in your type declaration is a place holder, so the variable will hold any typed instance of Vector, and that allows for the function to return the same vector you passed in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Java, when you iterator over a Vector<String[]> , why is .next() an Object
Vector's new method data() provides a const and non-const version. However string's data() method
vector<vector<string> > test for example. g++, you can do test.reserve(10); test[0] = othervector; test[9]
std::vector<Foo> vec; Foo foo(...); assert(vec.size() == 0); vec.reserve(100); // I've reserved 100 elems vec[50]
Does vector::operator= change vector capacity? If so, how? Does vector's copy constructor copy capacity?
std::vector<std::pair<std::string > > can be used to store a list of a pair of
vector< int > vect; int *int_ptr = new int(10); vect.push_back( *int_ptr ); I under
vector<int> myVector; and lets say the values in the vector are this (in this
vector<Flight> flights; while (!myReadFile.eof()) { flights.push_back(*(new Flight())); // read some info... } after the
Vector <Double> x = new Vector<Double>(); Vector <Integer> y = new Vector <Integer>(); System.out.print(x.equals(y));

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.