Let's say you're using a Vector to store several arrays. You may find it necessary to do something like:
<code><pre> int[] nextArray = (int[]) myVector.elementAt(0);</pre></code>
This is necessary because the elementAt() method is declared to return an Object. To use that Object as an array, you need to cast it to the appropriate type. This is OK at compile time because the compiler knows that an Object
could be an array. At run time, we will find out whether the object in question really
is an array - if not, a compile error occurs.
On the other hand, let's say you tried to do something like this:
<code><pre> int[] array = (int[]) someObject.toString();</pre></code>
The compiler will stop you right away, because there is no way that any
String returned by toString() could possibly be an array. No need to wait for runtime - we already know it's impossible.