W
Will
I get a Class Cast Exception at runtime with the following code, and
was wondering why this isn't allowed:
Vector v = new Vector();
//do some stuff to fill in v with a bunch of Strings
String [] s = (String [])(v.toArray());
The toArray method returns an Object [] so why can't I cast it to a
String [] if I know that everything in it will be a String? The only
workaround I've found is to make a second array and manually copy and
cast each element of the first array into the second array.
-Will
was wondering why this isn't allowed:
Vector v = new Vector();
//do some stuff to fill in v with a bunch of Strings
String [] s = (String [])(v.toArray());
The toArray method returns an Object [] so why can't I cast it to a
String [] if I know that everything in it will be a String? The only
workaround I've found is to make a second array and manually copy and
cast each element of the first array into the second array.
-Will