Class cast exception

From: Will (larkmore_at_aol.com)
Date: 10/18/04


Date: 18 Oct 2004 11:51:51 -0700

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