It may be clear to you, but the compiler doesn't have any way of knowing for certain that such a cast won't work. The example posted is trivial; quite often, a particular implementation is unknown at compile-time, so the compiler trusts you know what you're doing when you cast a reference.
posted 12 years ago
Only at runtime it can be made sure that the object cant be casted to a string .
Object is a super class of String . So casting an object to string cant cause a compile time error.
I started out with nothing..I still have most of it ...