Questions tagged [cloneable]

163 questions
0
votes
2 answers

Implementing ICloneable with protobuf-net

Can you please explain why the following piece of code fails to work? static void Main(string[] args) { var simpleObject = new SimpleObjectDTO { Id = 1, Name = "Jacob" }; const string format = "{2} object properties are: Id {0}…
Gena Verdel
  • 588
  • 5
  • 21
0
votes
1 answer

Java Cloneable or copy constructor, why would I use any of those? What do either of those strategies actually do?

The question I have is pretty noob like so please excuse me for my ignorance as I am a noob. I came across code some consultants wrote in the company I work for. When I tried delving into the code, I had no idea why a class was implementing some…
Horse Voice
  • 8,138
  • 15
  • 69
  • 120
0
votes
0 answers

Deep Copy for an array of strings

I need to demonstrate a code which implements deep copy for an array of strings in JAVA . Following is the code I developed.Anybody can confirm if it is correct or not? public class Paper implements Cloneable{ private String Type ; private…
Danial
  • 703
  • 1
  • 11
  • 26
0
votes
1 answer

How to create a deep copy of a linked list if objects stored in the list are not cloneable?

I have a linkedlist which contains objects that are not cloneable. What would be the most efficient way to deep copy the list? What I have tried is: List deepCopyListA = new LinkedList(aList); and it seems to work fine, but I am just…
Jas
  • 77
  • 1
  • 7
0
votes
3 answers

Is it required to use Clonable?

I read everywhere that if I call clone() without implementing Cloneable interface I will get CloneNotSupportedException. If I implement clone method in a class which does not implement Cloneable, I can still call clone() w/o exception. I mean…
0
votes
2 answers

Cannot refer to a class object A from the same class?

public class Car implements Cloneable{ private String name; private int price; Car(String name, int price) { this.name = name; this.price = price; } //copy constructor 1 Car(Car a) { price = a.price; name = a.name; } clone(Car…
user2089523
  • 63
  • 2
  • 8
0
votes
1 answer

Winforms Designer: When I copy\paste my custom control, need clone instead of pointer

I have a control called "MyControl", which has an object associated with it named "SettingsObject" which is an object that contains about 15-20 properties. I'm running into an issue where when I copy\paste my control using the visual studio…
greggorob64
  • 2,487
  • 2
  • 27
  • 55
0
votes
1 answer

CloneNotSupportedException, but I never call clone()

I am getting a CloneNotSupportedException, but I cannot find anywhere in my code where I call clone(). I have looked in the Java Docs and I cannot find any reason for this exception to be thrown other than me calling clone() on an object. Does…
JuiCe
  • 4,132
  • 16
  • 68
  • 119
-1
votes
2 answers

How clone() method of object class works?

Object class clone() method has native implementation which creates instance of child class and copies the state of source object to newly created instance. Question: clone() method of object class doesn't invoke constructor of child class then how…
user4811324
-1
votes
3 answers

Not able to see clone() method in suggestion list in java?

When I opened Object class source code I can see the clone() method in it. When I try to see clone() method in the method list doesn't show up (If I create object of MyClass as myClass and apply . dot operator it gives me suggestion of all…
user3571396
  • 113
  • 2
  • 11
-2
votes
1 answer

Behavior of JVM with Cloneable class

I know Cloneable is a marker interface and using it has pros and cons, but I want to know: What is memory strategy of JVM for Cloneable class?
-3
votes
1 answer

Cloning a Class In Java

I have this class that implements Cloneable. I only need a shallow copy here. Can anyone point to what is wrong with the java compliance here. public class EventSystem implements Cloneable{ private String enrollmentId; private String…
nnc
  • 790
  • 2
  • 14
  • 31
-5
votes
1 answer

example of a class that implements Cloneable Java

From what I have read about the Cloneable interface its a waste of time but we still have to study it for some reason. I have been going through sample questions but can not find an answer to the one below. Example of a class that implements…
Grimeire
  • 339
  • 1
  • 6
  • 19
1 2 3
10
11