Re: cast to sub-class or extending instance of super or a.n.other
- From: Roedy Green <see_website@xxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 11 Apr 2009 19:13:25 -0700
On Sun, 12 Apr 2009 09:10:45 +0800, "Richard Maher"
<maher_rj@xxxxxxxxxxxxxxxxxx> wrote, quoted or indirectly quoted
someone who said :
What's the best way of "new O = instance of A + stuff.
You need what is called a copy constructor. e.g.
new Dalmatian( dog );
Unfortunately, Java has no easy way of composing one. You must
manually copy field by field in the constructor -- code that will stop
working if Dog acquires any more fields. I proposed Java invent copy
constructors, a bit like COBOL MOVE CORRESPONDING, but everyone shot
me down.
A new Dog ( dog ) takes a Dalmatian and strips it down. You do this
only to save space. A Dalmatian object will do anything a Dog object
does.
If you check out the code for the Replicator you will see constructors
that go back and forth from MiniZip to BigZip etc. BigZip is just a
MiniZip with extra fields.
see http://mindprod.com/products1.html#REPLICATOR
--
Roedy Green Canadian Mind Products
http://mindprod.com
"The most significant trend in the US industry has been the decline in the amount
of energy recovered compared to energy expended. In 1916, the ratio was about 28
to 1, a very handsome energy return. By 1985, the ratio had dropped to 2 to 1,
and it is still dropping."
~ Walter Youngquist, Professor of Geology
By 2003, it had dropped to 0.5 to 1 in the US, making oil extraction no longer economically viable, no matter how high the price of crude.
.
- Follow-Ups:
- Re: cast to sub-class or extending instance of super or a.n.other
- From: Richard Maher
- Re: cast to sub-class or extending instance of super or a.n.other
- References:
- cast to sub-class or extending instance of super or a.n.other
- From: Richard Maher
- cast to sub-class or extending instance of super or a.n.other
- Prev by Date: Re: cast to sub-class or extending instance of super or a.n.other
- Next by Date: Re: Change logging level for Logger.throwing
- Previous by thread: Re: cast to sub-class or extending instance of super or a.n.other
- Next by thread: Re: cast to sub-class or extending instance of super or a.n.other
- Index(es):
Relevant Pages
|