Remember that legal casts are ruled by the "IS-A" test, why you can compile your code?, because ClassCastException is an Unchecked Exception, since extends from RuntimeException
ClassCastException ---IS-A--> RuntimeException (Another example of a possible legal cast).