Menu

Dynamic Cast

Mark Anthony Taylor (Shyreman)

Class instances can potentially implement more than one interface. Given a reference to one
such interface, it is possible to obtain a reference to the other interfaces by means of a dynamic
cast. This syntax is:

(cast <instance-name> -> <required-interface-name> <new-interface-variable-name>)

Where <instance-name> is the name of an existing interface variable.
And <required-interface-name> is the name of the new interface type.
And <new-interface-variable-name> is the name of the new interface variable.

The cast operation will attempt to find the alternative interface and assign a reference to the
variable with name new-interface-variable-name.

If the interface with name required-interface-name is not found in the object to which the instance
with name <instance-name> refers, then the interface variable with name <new-interface-variable-name>
will refer to the universal null object.

-- William Shakespeare

Example:
(cast entity -> IRobot robot)

Related

Wiki: Content

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.