Originally posted by Shailesh Misra:
I observed that Casting Object to Object Array and vice versa does not throw a ClassCastException. I was expecting a runtime error at 1.
Please help,
_____________________________________________________________
<pre>class test
{
public static void main(String[] args)
{
abc[] i = new abc[2];
Object o = new Object();
o = i;
i = (abc[])o ; // I was expectime error here at runtime.
}
}
class abc
{
int a = 1;
}
</pre>_____________________________________________________________
regards,
Shailesh
Why were you expecting a runtime error when you are casting back to the original type? Anything can be cast to an Object, even an array. If you cast the Object back to something else, ... for instance an int[] array rather than an abc[] array, ... you will get a compile time error.
[This message has been edited by Marilyn deQueiroz (edited October 17, 2001).]