Down Casting

In reply to HanP:

Remember that there is a distinction between classes variables and handles to class objects.

A class variable can only store handles to class objects that are the same type or extensions of that type.

$cast is called a dynamic cast because it checks at runtime if the source handle type is the same or an extension of the destination class variable type.

In your first $cast, the source handle type is not an extension of the destination class type, it is the opposite. Therefore an error.

In your second $cast, the source handle type is an extension of the destination class type. Therefore no error.