• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Deep Copy in java

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
class two implements serialization
{
int b;
}
Class one
{
int a;
two twoobject;
}

class demo
{
one oneobj1=new one();
one oneobj2;
//making deep copy using serialization(oneobj1 is copied to oneobj2)
}

If I deep copy oneobj1 to oneobj2 using serialization whether different copies of oneobj1 and oneobj2 will be created??
If I change the twoobject inside oneobj1 whether it will affect twoobject inside oneobj2??

Which is the best approch ??

 
Sheriff
Posts: 7135
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chnmaverick pionner wrote:
Which is the best approch ??


Cloning Objects - That might be what you need to do.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chnmaverick wrote:If I change the twoobject inside oneobj1 whether it will affect twoobject inside oneobj2??


Whether it's deep copy or shallow copy it will not change what one object refers to by changing other's same reference. But with shallow copy if you change the state of objects an object refers to then both (i.e: original and cloned) will see the changes.
 
chnmaverick pionner
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what do you mean by change in state of objects?
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chnmaverick pionner wrote:what do you mean by change in state of objects?


That is properties of the objects referred by the original object being cloned.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic