‎2008 Jan 21 6:35 AM
Hi,
When i assign a superclass reference to subclass instance it raises runtime error message which i hav mentioned below.
the statement which i used in the program is
subclass_instance ?= superclass_ref. " (DOWNCASTING)
" It was tried to assign a reference to a rereference variable using the
'CAST' operation ('?=' or 'MOVE ?TO').
However, the current content of the source variable does not fit into
the target variable."
can anyone tell me how to rectify this error. Thanks...
Regards,
Joseph.
‎2008 Jan 21 9:58 AM
My guess is you've something like this:
data: superclass_ref type ref to superclass,
subclass_instance type ref to subclass.
create object superclass_ref.
subclass_instance ?= superclass_ref.
The problem is that the object superclass_ref is of type superclass. When you try to downcast, you can't because superclass doesn't have, for example, all the attributes of subclass. In order to use down casting, the receiving object reference MUST be of the type of the subclass. So you need something like this:
create object superclass_ref TYPE subclass.
subclass_instance ?= superclass_ref.
Matt