Questions tagged [cloning]

Cloning refers to the making of an exact copy (deep copy) of any kind of object. It is the opposite of shallow copying, in which a reference to particular object is copied, not the object itself.

Cloning refers to the making of an exact copy (deep copy) of any kind of object. It is the opposite of shallow copying, in which a reference to particular object is copied, not the object itself.

377 questions
9
votes
4 answers

Cloning vs. Instantiating a new class

Is cloning good practice in this case? How to do it better? public ModelCollection startParsing() { return parseFeed(new ModelSpecialEntry); } public ModelCollection parseFeed(ModelEntry pattern) { ModelCollection modelCollection = new…
OneWorld
  • 17,512
  • 21
  • 86
  • 136
8
votes
1 answer

C# Clone System.Data.Entity.DynamicProxies to the actual (non proxied) class?

Possible Duplicate: EF4 Cast DynamicProxies to underlying object I'm trying to figure out how to clone or convert a System.Data.Entity.DynamicProxies into it's actual class. Eg: System.Data.Entity.DynamicProxies.Currency_F4008E27DE_etc is the…
JK.
  • 21,477
  • 35
  • 135
  • 214
7
votes
1 answer

Clone an Object that I can't add ICloneable to

I am trying to create a shallow copy (new instance) of an object, without manually setting each field. This object is not a type I have the ability to modify, so I cannot go into the object and implement ICloneable ... I am a bit stuck. Is there…
MattW
  • 12,902
  • 5
  • 38
  • 65
7
votes
4 answers

Deep Cloning of Java objects (Not beans)

The project that I am currently working on has lot of objects that are serialized in order to get a deep copy of the the existing object. This works fine until we have multiple calls at runtime in some cased we have 100, 200, or even 1000 calls…
K.M
  • 154
  • 3
  • 11
7
votes
1 answer

Cloning a FileList object in JavaScript for file upload?

Alright, here is my situation. I have a JavaScript class that deals with AJAX form submissions and other related synchronous and asynchronous requests. It gathers data, then sets this data to a temporary storage for the request and then makes the…
kingmaple
  • 4,200
  • 5
  • 32
  • 44
7
votes
4 answers

Why classes in Java are not cloneable by default

In Java, to make a class cloneable, we need to implement Cloneable interface. Implementing this interface, is just to say that this class supports cloning. But what is the motive of Java language designers for not making "allowed-to-clone" as…
Kaushik Lele
  • 6,439
  • 13
  • 50
  • 76
6
votes
1 answer

Avoid updation of cloned testcase when master copy is updated in VSTS

I have a Master Copy of test cases, which I will be cloning for every testing cycle. Changes in Master Copy test cases gets reflected in already cloned test cases. How can i avoid this?
Sagar Patil
  • 1,400
  • 15
  • 29
6
votes
5 answers

Faster way to clone

I am trying to optimize a piece of code that clones an object: #region ICloneable public object Clone() { MemoryStream buffer = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(buffer, this); …
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
6
votes
3 answers

Java: How to deep-clone a HashSet neatly?

I have a HashSet of MyObject that I need to clone. If MyObject implements a copy-constructor, what is the easiest, neatest way to clone Set myObjects Obviously I could do something like: Set myNewObjects = new Set(); …
Paul
  • 3,318
  • 8
  • 36
  • 60
6
votes
4 answers

Cloning Lua state

Folks, is there a way to clone a Lua state? In my game application the initialization procedure of the Lua virtual machine is pretty heavy(about 1 sec, since many scripts are loaded at once). I have a separate Lua VM for each autonomous agent and…
pachanga
  • 3,003
  • 4
  • 30
  • 45
5
votes
3 answers

Why do we implement Cloneable even if we can go for deep cloning using the following snippet

public class Color { String color; Color(String color) { this.color=color; } } public class ColoredCircle { int x; Color color; ColoredCircle(int x, Color color) { this.x=x; this.color=color; } public Object testClone() { …
Arijit Dasgupta
  • 325
  • 3
  • 14
5
votes
6 answers

How can a derived C++ class clone itself via a base pointer?

Here's what I'm trying to do (this code doesn't work): class Base { virtual Base *clone() { return new Base(this); } virtual void ID() { printf("BASE"); }; class Derived : publc Base { virtual Base *clone() { return new Derived(this);…
wanlessv
  • 51
  • 1
  • 3
5
votes
1 answer

Duplicating a canvas many times: clone the canvas or copy the image data?

One of my interface elements is being rendered using the HTML5 element and associated JavaScript API. This element is used in several places on the same screen and on multiple screens throughout the app. What is the most efficient way to…
Daveh0
  • 952
  • 9
  • 33
5
votes
3 answers

Java return copy to hide future changes

In Java, say you have a class that wraps an ArrayList (or any collection) of objects. How would you return one of those objects such that the caller will not see any future changes to the object made in the ArrayList? i.e. you want to return a…
Lehane
  • 47,588
  • 14
  • 53
  • 53
5
votes
5 answers

What is the difference between cloning the object with .clone() method and = sign?

I am really confused about what is the difference between .clone() method or simply putting the = sign between objects while trying to clone it. Thank You.
Robert
  • 103
  • 2
  • 8
1
2
3
25 26