ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Deep Copy vs. Shallow Copy in Scala

Scala | Deep Copy vs. Shallow Copy: Here, we will learn about deep copy and shallow copy in Scala. Both are object coping techniques.
Submitted by Shivang Yadav, on December 20, 2020

Prerequisite: Scala objects

Object Copy is a way to copy the contents of an object to another object.

There can be two methods to copy objects in Scala,

  1. Deep Copy
  2. Shallow Copy

1) Deep Copy

This a method of copying contents from one object to another object. In this copying technique, the changes made in the copied object are not reflected in the original object.

This shows that the new object copy created and the original object do not share the same memory location.

The figure below illustrates the Deep Copy,

deep copy

2) Shallow Copy

The shallow copy method of copying contents is a technique in which the changes made in the copied object are reflected in the original object.

This shows that the new object copy created and the original object share the same memory location.

The figure below illustrates the Shallow Copy,

shallow copy

Note: Shallow copy is used in object creation for case class in Scala.

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.