The following is from the reference manual:
When $cast is applied to class handles, it succeeds in only three cases:
- The source expression and the destination type are assignment compatible, that is, the destination is
the same type or a superclass of the source expression. - The type of the source expression is cast compatible with the destination type, that is, either:
— the type of the source expression is a superclass of the destination type, or
— the type of the source expression is an interface class (see 8.26)
and the source is an object that is assignment compatible with the destination type. This type of
assignment requires a run-time check as provided by $cast. - The source expression is the literal constant null.
I don’t understand the line after “and”, first it says the for it needs to be cast compatible which means source expression is of the superclass type and then after “and” it says the expressions must be assignment compatible. How can it be both?