Questions tagged [clone]

A clone is a copy of an object with all of the same attributes, data, and methods as the original object. Or a software system that is designed to mimic another system.

A clone is a copy of an object with all of the same attributes, data, and methods as the original.

In practice, an object is cloned when you want to duplicate the original exactly and then change it in some way, such as changing a due date on a recurring task or linking it to a different object in a database hierarchy.

In computing, a clone is a hardware or software system that is designed to mimic another system.

See Also:

4519 questions
251
votes
5 answers

The difference between fork(), vfork(), exec() and clone()

I was looking to find the difference between these four on Google and I expected there to be a huge amount of information on this, but there really wasn't any solid comparison between the four calls. I set about trying to compile a kind of basic…
user476033
  • 4,607
  • 8
  • 32
  • 35
247
votes
16 answers

MySQL: Cloning a MySQL database on the same MySql instance

I would like to write a script which copies my current database sitedb1 to sitedb2 on the same mysql database instance. I know I can dump the sitedb1 to a sql script: mysqldump -u root -p sitedb1 >~/db_name.sql and then import it to sitedb2. Is…
uclajatt
  • 4,003
  • 4
  • 21
  • 11
241
votes
6 answers

What's the difference between Ruby's dup and clone methods?

The Ruby docs for dup say: In general, clone and dup may have different semantics in descendent classes. While clone is used to duplicate an object, including its internal state, dup typically uses the class of the descendent object to create the…
cali-1337500
  • 2,421
  • 2
  • 14
  • 8
205
votes
9 answers

How do I create a copy of an object in PHP?

It appears that in PHP objects are passed by reference. Even assignment operators do not appear to be creating a copy of the Object. Here's a simple, contrived proof: b = "after";…
Nick Stinemates
  • 41,511
  • 21
  • 59
  • 60
201
votes
10 answers

How to clone an InputStream?

I have a InputStream that I pass to a method to do some processing. I will use the same InputStream in other method, but after the first processing, the InputStream appears be closed inside the method. How I can clone the InputStream to send to the…
Renato Dinhani
  • 35,057
  • 55
  • 139
  • 199
194
votes
11 answers

Java: recommended solution for deep cloning/copying an instance

I'm wondering if there is a recommended way of doing deep clone/copy of instance in java. I have 3 solutions in mind, but I can have miss some, and I'd like to have your opinion edit: include Bohzo propositon and refine question: it's more about…
Guillaume
  • 5,488
  • 11
  • 47
  • 83
178
votes
14 answers

How do I clone a generic List in Java?

I have an ArrayList that I'd like to return a copy of. ArrayList has a clone method which has the following signature: public Object clone() After I call this method, how do I cast the returned Object back to ArrayList?
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
167
votes
18 answers

Clone a List, Map or Set in Dart

Coming from a Java background: what is the recommended way to "clone" a Dart List, Map and Set?
Patrice Chalin
  • 15,440
  • 7
  • 33
  • 44
146
votes
6 answers

Clone() vs Copy constructor- which is recommended in java

clone method vs copy constructor in java. which one is correct solution. where to use each case?
Jothi
  • 14,720
  • 22
  • 68
  • 93
146
votes
21 answers

How can I clone an Object (deep copy) in Dart?

Is there a Language supported way to make a full (deep) copy of an Object in Dart? If multiple options exist, what are their differences?
george koller
  • 3,721
  • 6
  • 23
  • 27
145
votes
8 answers

How to copy a Map into another Map?

How do I clone/copy a Map in JavaScript? I know how to clone an array, but how do I clone/copy a Map? var myArray = new Array(1, 2, 3); var copy = myArray.slice(); // now I can change myArray[0] = 5; & it wont affect copy array // Can I just do…
sazr
  • 24,984
  • 66
  • 194
  • 362
142
votes
11 answers

Copying a HashMap in Java

I am trying to keep a temporary container of a class that contains member : HashMap myobjectHashMap A class called myobjectsList Then I do myobjectsListA = new myobjectsList(); myobjectsListB = new myobjectsList(); then: Add some…
user691305
  • 1,560
  • 2
  • 9
  • 12
140
votes
6 answers

How to clone and change id?

I need to clone the id and then add a number after it like so id1, id2, etc. Every time you hit clone you put the clone after the latest number of the id. $("button").click(function() { $("#id").clone().after("#id"); });
user1324780
  • 1,649
  • 3
  • 14
  • 11
137
votes
9 answers

How do you clone a BufferedImage

I have an object which has many bufferedimages in it, I want to create a new object copying all the bufferedimages into the new object, but these new images may be altered and i don't want the original object images to be altered by altering the new…
f1wade
  • 2,877
  • 6
  • 27
  • 43
133
votes
29 answers

git clone error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054

I'm having trouble cloning a repo on git. I've been trying for to days and have tried quite a few solutions (in most the problem was slightly different but seemed to apply) but nothing has done anything to make a difference. I've tried switching off…
user8612746
  • 1,331
  • 2
  • 8
  • 4