I've seen the problem before and learned just do the interation and casts without toArray().
My listing of the Java API on Vector lists only two methods toArray()
One that takes no parameters and one that takes an Object[]. The text
with the latter says that it sorts the array (with no information about
how it sorts, ascending?)
There's nothing about toArray(Class?) or any other overloaded operators.
Is the API faulty? Am I looking at the wrong API ?
Is this only Java 1.3? Somewhere else?
John Zukowski wrote:
>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
-- Thom Burnett
