I would like to create a new object by converting an object of a base class to the type of a sub class
You could create a constructor that takes a reference to the original object but it would still have to explicitly initialize all the variables.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Paul M. Santa Maria, SCJP
My base objects have functionality over a certain lifetime some of them may never become objects belonging to the subclass. What I am trying to avoid is re-initializing the instance data of my base objects. The main reason is that subsequent changes to my base class will require ALL my object conversions to change.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
The structure size of the sub-object is likely to be larger than the base object
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Thus, to "promote" an object, the underlying struct size would have to change. Java doesn't do this. Period. Could it? possibly. Is is necessarily a good idea? Maybe, but probably not.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
However I am still struggling to see WHY the instance data belonging to my parent class can not be inherited to child objects.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|