On Tue, 2 Nov 1999, Yohans Mendoza wrote:

> here's the piece, plese help
> 
> public STable(Vector fieldsv, Vector rowsv)
>       {
>                 originalRows = (Vector)rowsv.clone();
>               rows = (Vector)rowsv.clone();
>               ...
>       }
> now, the problem is that when rows changes originalRows changes too.
> the parameter is a vector of vectors, so I'm guessing that's messging
> things up, right? 

You need to clone every element in the Vector also.  By default, Vector's
clone() only does a shallow copy, whereas you seem to want a deep copy.

Remember that Java uses a reference data model, so when you clone the
Vector, the second vector "rows" has copies of the references from the
first vector "originalRows", but the references STILL point back to the
original objects in "originalRows".  Thus, adding or removing elements
from the cloned vector will work as expected, but changing the actual
elements in the vector will affect the original.

A basic Java mailing list such as those hosted by Sun or the Java
newsgroups will be more helpful here.

. . . Sean.



----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to