Basic concepts:
Shallow copy: The field of the object is copied, and the object referenced by the field is not copied. The Copied object and the original object are only referenced by different names, but they share an object. Changes to any object
Ava has three methods to create an object instance.
1. New
Generally, the Java keyword new is used to create an object instance.
If there is a something class, you can use the following statement to create an object instance of the something
Package cn.hncu.day7.clone.v1;Cloning the routine:1th step: Rewrite the Clone () method of the user class for outside invocation. Because the outside class cannot directly invoke the Clone () method in the parent class of the user
Java basic usage tips: Two Methods of deep copy
(1) shallow copy (shallow clone)
All variables of the Copied object contain the same value as the original object, and all references to other objects still point to the original object. In other
in the. NET class Library, object cloning exists widely in various types of implementations, and all types that implement the ICloneable interface have the ability to clone their object instances. So deep and shallow copies of this article are
One of the advantages of the Java language is that it removes the notion of pointers, but it also causes many programmers to ignore the distinction between objects and references in programming, and this article tries to clarify this concept. And
What is Shadow clone.
The following example contains three class Unclonea,cloneb,clonemain. The Cloneb class contains a Unclonea instance and an int type variable, and overloads the Clone () method. The Clonemain class Initializes an instance of the
Before we get to the formal topic, let's take a look at the next deep copy and the first copy concept:
Shallow copy:
Creates a new object that has an exact copy of the original object's attribute value, and if the attribute is a basic type, the
There are four ways to create objects in a Java program:Call the new statement to create an object, the most common oneUsing reflection to create an object, call the Newinstance () instance method of the Java.lang.Class or
Java design mode-Original Model mode and java design mode Model
Introduction
The original model mode belongs to the object creation mode. Specify the type of the object to be created through a prototype object, and then use the method of
I recently saw some netizens asking questions about strong conversion of objects in C # On the Forum. Although I have been familiar with C #, I was the first to contact this feature, so here we will find some materials to share with you.
I.
Copying is getting a copyCloning is copying a copy of an object. However, there may be basic data Types in an object, such as: Int,long,float, etc., and also contain non-basic data types such as (arrays, collections, etc.)The value of the base type
Recently, I was reading objective Java, where I talked about cloning, so today I want to study cloning.
We all know that there are two better ways to copy a corresponding one, one is serialization, and the other is cloning. It is convenient to use
Hash is a data type extended by the prototype author. In essence, it is a common JavaScript Object (Note: Do not tangle with any JavaScript variables that are objects. Here we will talk about new object (), and then expand some other methods on this
Valid C # principle 27: Avoid using icloneable
Item 27: Avoid icloneable
Icloneable looks like a good idea: after implementing the icloneable interface for a type, you can support copying. If you do not want to support copying, do not implement
To understand the prototype mode, you must first understand the shortest replication and deep replication in Java. In some cases, replication is also called cloning. Java provides these two cloning methods.
Shortest: all the variables of the cloned
Object cloning: it is the copy of Object Instantiation. in actual application, we actually use object copying, such as value type assignment, mutual assignment of reference types, value-Type Packing operations. In fact, these are all object cloning
I implemented it myself:
Copy codeThe Code is as follows: public class A implements Cloneable {
Public String str [];
A (){Str = new String [2];}
Public Object clone (){A o = null;Try {O = (A) super. clone ();} Catch (CloneNotSupportedException e )
When I design the database cache layer, I need to make a deep copy of the data so that the data objects that the user operates are not shared.This idea is actually similar to Erlang, which is to solve concurrency problems with data not sharing.1.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.