Originally posted by Pho Tek: Why can't I cast an Object to String ?
How did you try? Can you show us some code? What is the Object containing?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
It doesn't matter what the Object is containing - if it was created using new Object, it really is an Object array even if all the elements are Strings. No Amount of casting can change this. However, if the array is really a String (created using new String for example) and you're just using a reference variable of type Object to refer to it, then you can cast. E.g.will compile OK, but will throw a ClassCastException at runtime because the array is not a String - just an Object containing Strings. However this works: This illustrates why the cast in the previous example was allowed to succeed at compile time - a reference which is declared to be of type Object could hold a reference to a String (as it does in the second example). So the cast must be allowed at compile time - but it can still be invalid at run time. This may seem strange, but it's nearly identical to the waycompiles but does not run, and compiles and runs. [ May 30, 2002: Message edited by: Jim Yingst ]