Patch: super.clone() and CloneNotSupportedException

Per Bothner per@bothner.com
Sun Jul 20 16:30:00 GMT 2003


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/




More information about the Java-patches mailing list