Hi All,
Why java copies Address instead of values when we assign like this
ArrayList test=new ArrayList();
ArrayList test1=new ArrayList();
test=test1;//Both share the same memory .
As far as i Know this can be avoided by using the Clone Method. I can go for Clone supported by object if the using object doesn't contain any object itself i.e it contains only primitive data type or else we need to explicitly implement cloneable interface .Why java doesn't support the copy by value method as it supports equals (A method to override == ).
Thanks
Maruthi
[ December 22, 2005: Message edited by: Michael Ernest ]
Why java copies Address instead of values when we assign like this
ArrayList test=new ArrayList();
ArrayList test1=new ArrayList();
test=test1;//Both share the same memory .
As far as i Know this can be avoided by using the Clone Method. I can go for Clone supported by object if the using object doesn't contain any object itself i.e it contains only primitive data type or else we need to explicitly implement cloneable interface .Why java doesn't support the copy by value method as it supports equals (A method to override == ).
Thanks
Maruthi
[ December 22, 2005: Message edited by: Michael Ernest ]