Java provides a mechanism for creating copies of objects called cloning. There are two ways to make a copy of an object called shallow copy and deep copy.
Shallow copy is a bit-wise copy of an object. A new object is created that has an exact copy of the values in the original object. If any of the fields of the object are references to other objects, just the references are copied. Thus, if the object you are copying contains references to yet other objects, a shallow copy refers to the same subobjects.
Deep copy is a complete duplicate copy of an object. If an object has references to other objects, complete new copies of those objects are also made. A deep copy generates a copy not only of the primitive values of the original object, but copies of all subobjects as well, all the way to the bottom. If you need a true, complete copy of the original object, then you will need to implement a full deep copy for the object.
Java supports shallow and deep copy with the Cloneable interface to create copies of objects. To make a clone of a Java object, you declare that an object implements Cloneable, and then provide an override of the clone method of the standard Java Object base class. Implementing Cloneable tells the java compiler that your object is Cloneable. The cloning is actually done by the clone method.
Learn and Share about AI, GenAI, AEM, Angular, React, Tailwind, Mobile Development, Node.js, MicroServices and Cloud
-- ideas can change everything!
Subscribe to:
Post Comments (Atom)
Get in the Vibe with Copilot Agent: Supercharging Your Coding Flow
Have you ever felt "in the zone" while coding? That feeling of seamless flow, where the code practically writes itself? That's...

-
AEM as a Cloud Service (AEMaaCS) – Architecture Adobe Experience Manager (AEM) is one of the leading CMS from Adobe and is part of Adobe Ex...
-
Some time while migration or for auditing purposes we need to know where a particular component/template or any other resource have been u...
-
I stumbled on an issue when I was using neab with AEM 6.3. I created few neba ResourceModels and when I tried to access neba Model Registr...
No comments:
Post a Comment