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

Creating a copy of an object in C#

Please have a look at the code below (excerpt from a C# book): public class MyClass { public int val; } public struct myStruct { public int val; } public class Program { private static void Main(string[] args) { MyClass…
afaolek
  • 8,452
  • 13
  • 45
  • 60
125
votes
9 answers

How to properly override clone method?

I need to implement a deep clone in one of my objects which has no superclass. What is the best way to handle the checked CloneNotSupportedException thrown by the superclass (which is Object)? A coworker advised me to handle it the following…
Cuga
  • 17,668
  • 31
  • 111
  • 166
117
votes
24 answers

How to fix 'The project you were looking for could not be found' when using git clone

I am trying to clone a project from gitlab to my local machine. I have been granted rights as a developer, and use the command 'git clone None of the protocols work (ssh and https neither work) The error message I am getting: remote: The project…
tijnster
  • 1,387
  • 3
  • 8
  • 12
68
votes
8 answers

Fastest Way to do Shallow Copy in C#

I wonder what is the fastest way to do shallow copying in C#? I only know there are 2 ways to do shallow copy: MemberwiseClone Copy each field one by one (manual) I found that (2) is faster than (1). I'm wondering if there's another way to do…
tep
  • 1,237
  • 2
  • 13
  • 13
22
votes
3 answers

Is there a much better way to create deep and shallow clones in C#?

I have been creating object for a project and there are some instances that I have to create a deep copy for this objects I have come up with the use of a built in function for C# which is MemberwiseClone(). The problem that bothers me is whenever…
Allan Chua
  • 9,305
  • 9
  • 41
  • 61
20
votes
5 answers

Why is cloning (in .NET) so difficult?

In the past I had the need to clone objects, only to find that they don't implement a Clone() method, forcing me to do it by hand (create a new instance and copy all properties from the original to the new one) Why isn't cloning as easy as…
juan
  • 80,295
  • 52
  • 162
  • 195
20
votes
1 answer

How do I get `git clone --recursive` to recreate submodules' remotes and branches?

I have a project with a handful of submodules. Many of them are cloned from a GitHub fork to which I've added a branch for my custom mods. A typical setup is like thus: In local folder: MyProject1/Frameworks/SomeAmazingRepo/ $ git branch…
Hari Honor
  • 8,677
  • 8
  • 51
  • 54
19
votes
7 answers

How to deep copy a class without marking it as Serializable

Given the following class: class A { public List ListB; // etc... } where B is another class that may inherit/contain some other classes. Given this scenario: A is a large class and contains many reference types I cannot mark B as…
Gaddigesh
  • 1,953
  • 8
  • 30
  • 41
18
votes
4 answers

Can I connect git if I downloaded the code as zip

I downloaded the latest code of a repositiry as zip but now I want to be able to work with branches too. Is there anyway I can use the folder as a git repository just like what I have if I clone the project?
Amit
  • 427
  • 4
  • 16
17
votes
1 answer

Spring: Create new instance of bean for each call of get method

I have next situation: Connection manager should have each time one object of ConnectionServer and new objects of DataBean So, I have created these beans and configured out it spring xml.
Sergii Zagriichuk
  • 5,389
  • 5
  • 28
  • 45
16
votes
2 answers

How to clone a multidimensional array in java?

Edit 2: Below is a code snippet based on DuffyMo's response that illustrates how to get around the limitations of cloning for multidimensional arrays using System.arraycopy. import java.util.Arrays; public class Randar { public static int[][]…
vancan1ty
  • 563
  • 1
  • 4
  • 16
13
votes
3 answers

Redux: why using Object.assign if it is not perform deep clone?

One core concept in Redux is, states are immutable. However, I saw many examples, including in Redux docs using javascript Object.assign. Then, I saw this warning in MDN: For deep cloning, we need to use other alternatives because Object.assign()…
yuval.bl
  • 4,890
  • 3
  • 17
  • 31
12
votes
4 answers

How to Clone from GitHub

I'm new using GitHub. I'm trying to clone my first file from a users repo. I keep receiving this error: Permission denied (publickey). fatal: Could not read from remote repository When I check to verify the public key is attached to my GitHub…
tmcd
  • 355
  • 3
  • 16
11
votes
1 answer

Why does cloning my custom type result in &T instead of T?

use generic_array::*; // 0.12.3 use num::{Float, Zero}; // 0.2.0 #[derive(Clone, Debug)] struct Vector> { data: GenericArray, } impl> Vector where T: Float + Zero, { fn dot(&self,…
Maik Klein
  • 15,548
  • 27
  • 101
  • 197
11
votes
4 answers

Deep Cloning of Collections in java

Recently I faced this question in an Interview: Write a function to return a deep clone instance of class Drawing public class Drawing{ public List shapes=new LinkedList(); } where shape is an abstract class having many concrete…
mahan07
  • 887
  • 4
  • 14
  • 32
1
2 3
25 26