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
77
votes
4 answers

jquery clone div and append it after specific div

From the picture above, I want to clone the div with id #car2 and append it after the last div with id start with car, in this example id #car5. How can I do that? Thanks. This is my try code: $("div[id^='car']:last").after('put the clone div…
cyberfly
  • 5,568
  • 8
  • 50
  • 67
77
votes
8 answers

Deep clone utility recommendation

Is there any utility for deep cloning for java collections: Arrays Lists Maps NOTE: prefer some solution without usage of serialization, but with use of Object.clone() method. I can be sure that my custom object will implement clone() method and…
Juraj
  • 1,951
  • 2
  • 21
  • 30
76
votes
7 answers

Cloning an object in JavaScript

The below first logs 0, and then logs 1. How do I store a copy of the object, rather than a reference to it? debug.log(vi.details.segment); vi.nextSegment = vi.details; vi.nextSegment.segment++; debug.log(vi.details.segment);
Matrym
  • 16,643
  • 33
  • 95
  • 140
75
votes
4 answers

Deep copy, shallow copy, clone

I need clarification on the differences between deep copy, shallow copy, and clone in Java
trs
  • 2,454
  • 13
  • 42
  • 61
73
votes
1 answer

How do I clone a View?

My question is almost exactly this question: Clone textview to append it to a ViewGroup However, I was inflating a view, and then attempting to clone it at the object level for performance reasons (I don't want to parse XML every single time), so…
SapphireSun
  • 9,170
  • 11
  • 46
  • 59
73
votes
2 answers

Any way to clone HTML5 canvas element with its content?

Is there any way to create a deep copy of a canvas element with all drawn content?
Evgenyt
  • 10,201
  • 12
  • 40
  • 44
72
votes
3 answers

How to clone a struct storing a boxed trait object?

I wrote a program that has the trait Animal and the struct Dog implementing the trait. It also has a struct AnimalHouse storing an animal as a trait object Box. trait Animal { fn speak(&self); } struct Dog { name: String, } impl…
Denis Kreshikhin
  • 8,856
  • 9
  • 52
  • 84
69
votes
16 answers

How to clone an array of objects in PHP?

I have an array of objects. I know that objects get assigned by "reference" and arrays by "value". But when I assign the array, each element of the array is referencing the object, so when I modify an object in either array the changes are reflected…
DisgruntledGoat
  • 70,219
  • 68
  • 205
  • 290
68
votes
3 answers

java.util.Date clone or copy to not expose internal reference

It is best practice not to expose the internal references of an Object (Entity). So if an Object has a field of type java.util.Date then for example the getter for this field should return not the original date but an copy of it. But for an…
Ralph
  • 118,862
  • 56
  • 287
  • 383
68
votes
2 answers

How to clone or copy a set in Python?

For copying a list: shallow_copy_of_list = old_list[:]. For copying a dict: shallow_copy_of_dict = dict(old_dict). But for a set, I was worried that a similar thing wouldn't work, because saying new_set = set(old_set) would give a set of a set? But…
Evgeni Sergeev
  • 22,495
  • 17
  • 107
  • 124
66
votes
3 answers

What is the method MemberwiseClone() doing?

I am confused with this code below, Developer devCopy = (Developer)dev.Clone(); Clone method of Developer class just creating a Employee clone, then how developer get another clone of developer. public abstract class Employee { public abstract…
Syed Tayyab Ali
  • 3,643
  • 7
  • 31
  • 36
65
votes
3 answers

Explain clones info in Github's Traffic tab

In a recent question I made, one of the answers pointed to another answer in another question where a way to explore the forks and clones of a public Github repo was shared. I went ahead and did that with my own public repo and came up with this…
Gabriel
  • 40,504
  • 73
  • 230
  • 404
65
votes
9 answers

How to clone a JPA entity

I have a JPA entity already persisted in the database. I would like to have a copy of it (with a different id), with some fields modified. What is the easiest way to do this? Like: setting it's @Id field to null and persisting it will work? will I…
krisy
  • 1,508
  • 1
  • 14
  • 32
64
votes
8 answers

Is there a method to clone an array in jQuery?

This is my code : var a=[1,2,3] b=$.clone(a) alert(b) Doesn't jQuery have a 'clone' method? How can I clone an array using jQuery?
zjm1126
  • 34,604
  • 53
  • 121
  • 166
63
votes
6 answers

How do I clone a sub-folder of a repository in Mercurial?

I have a Mercurial repository containing a handful of related projects. I want to branch just one of these projects to work on it elsewhere. Is cloning just part of a repository possible, and is that the right way to achieve this?
James Hopkin
  • 13,797
  • 1
  • 42
  • 71