What Are The Rules For Object Reference Casting

: Casting from Old types to Newtypes

Compile time rules :

– When both Oldtypes and Newtypes are classes, one should be subclass of the other

– When both Oldtype ad Newtype are arrays, both arrays must contain reference types

(not primitive), and it must be legal to cast an element of Oldtype to an element of

Newtype

– You can always cast between an interface and a non-final object

Runtime rules :

– If Newtype is a class. The class of the expression being converted must be Newtype

or must inherit from Newtype

– If NewType is an interface, the class of the expression being converted must

implement Newtype