Implement the Cloneable interface on your ActionForm and call XXX newForm = (XXX)oldForm.clone(). Read the JavaDoc on Cloneable and the Object.clone() method for more information.

-- Jeff

dmu2201 wrote:
Sebastian Ho wrote:

Now this is a Java question, if "XXX newForm = (XXX) form" resulted in
form and newForm having the same memory space? How do I really make a
duplicate copy with different memory space (beside using new, or is new
the only solution)?
Sebastian Ho



Since this is Java and not C++ or C, you don't really have much control over the memory space or the way that Java passes your objects around. If you want to make a copy you have to use new. Otherwise Java will just use the same object all the way.

If you want a copy you have to create a new object of the same type and call all the set methods on the new object passing the values from the old object.
Another solution might be to have a constructor which takes a reference to the same object, which can then set all the values again:


XXX(XXX other)
{
     this.variable0 = other.variable0;
      this.variable1 = other.variable1;
     //and so on...
}

No matter what method you choose, I personnally prefer the last one, you have to use new! Don't think so much of the memory consumption since the GC will take care of that for you.

Enjoy...
Claus


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to