This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

about clone

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone.
My problem is
1.What is the different from deep and shallow copy.
2.What is the example.
Thanks.
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A shallow copy just copies all mutable object references as is. A deep copy clones every object so that the references refer to different objects.
Shallow copy:
Shallow copy example

Deep copy example

Notice that in the deep copy I created a new double[] and copied the contents of it into my clone and I created a new Map with HashMap's copy constructor. Note that on the primitive int and the String member that there is no difference in the clone methods. The reason for this is that primitive instance variables of objects of the same class always have unique storage for each object. As for the String member, Strings are immutable so there is no danger that the cloned object could change the value of the String in the parent.
 
robert chen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.
Thanks for your help.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic