Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When to use shallow copy and deep copy ?

 
Praveen Kumar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I know concepts about shallow copy and deep copy. Just i want to know when we will go for shallow copy and deep copy ?. Please suggest some examples that would be great.

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends entirely on what the needs are for the program you are writing - there's no general answer to this question.

I'd avoid copying objects as much as possible - it costs performance and memory. If you make your data objects immutable, you'll never need to copy them.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic