>Now, a vector that calls toArray() that returns an array of objects, but
>when you cast that array to one of strings it throws a ClassCastException
>
> Vector v = new Vector();
> v.addElement("A");
> v.addElement("B");
> v.addElement("C");
>
> Object[] objects = v.toArray();
> String[] strings = (String[])objects; /* blows up here */
>
>What's the difference between the last two lines of each section of code.
Because toArray() actually returns an Object array. It never was a String
array. It just happens to hold String objects.
There is an overloaded version of toArray() that let's you pass in the type
of array you want. Use it instead if you want to treat the array returned
as some type other than Object.
J
John Zukowski, Content Director
http://www.jGuru.com -- Your view of the Java Universe
Focus on Java Guide - http://java.about.com
The limits of my language are the limits of my world. - Wittgenstein
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing