Hi,

i'm trying to migrate an object from a given class A to a subclass of A with new inst vars. Can't get it to work.

I have a class and an instance of it, say:

Object subclass: #A
    instanceVariableNames: ''

|a|

a := A new.

A has no instance variables. Now i create a subclass B of A with a new inst var:

A subclass: #B
    instanceVariableNames: 'x'

I want to do the following:

B adoptInstance: a

It does'nt work, for what i understand it is because the format of the classes are different (B has an inst var and A has not).

 

How can i make the a object become an instance of B (subclass of a's class), making a acquiring the new inst var x (and in more complex cases keeping its own previous inst vars) ?

 

Steven.