This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: super.clone() and CloneNotSupportedException


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/



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]