This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: Patch: super.clone() and CloneNotSupportedException
- From: Per Bothner <per at bothner dot com>
- To: gnustuff at thisiscool dot com
- Cc: java-patches at gcc dot gnu dot org
- Date: Sun, 20 Jul 2003 09:33:17 -0700
- Subject: Re: Patch: super.clone() and CloneNotSupportedException
- References: <2ZCAJGK8685TP1V86IDECQKIGRLVPWS.3f1abf47@p733>
Mohan Embar wrote:
I thought about this, but I don't know enough about gcj internals to
understand whether this works or not. For someone like me who doesn't
know too much about gcj, x looks like an object reference, so the above
code would be incorrect because you'd be creating a shallow copy of x
instead of a deep copy.
Yes and no. This only copies the reference "shallowly", but sometimes
that is the correct thing in a clone.
More generally, what youd'd have to do is:
class A {
gnu.gcj.RawData x;
native RawData copy_x(RawData x);
A copy() {
A a = new A();
a.x = copy_x(this.x);
return a;
}
}
But copy_x could just return it's argument. It could increment a
reference count. It could alloacte a new native object. It could
allocate a new Java object. Or some combination may be appropriate.
Not all copyable objects are trees.
--
--Per Bothner
per@bothner.com http://per.bothner.com/