Hi,
I am curious about why does
Java compiler allow type casting of an object of a super class into an instance of a subclass.
E.g. the following code compiles fine but fails at runtime.
I understand that the compiler wants to give benefit of doubt to sc under the assumption that the code that lead upto line 2 may have created bc to be really of type SubClass and not a BaseClass.
But isn't this a dangerous assumption to be made. Shouldn't it be more preferable to throw a compiler error than to await a confrontation with Runtime ClassCastException?
[ July 24, 2007: Message edited by: Vivian Josh ]