cloneable Questions

2

Solved

Code behind: class A implements Cloneable { int i, j; A(int i, int j) { this.i = i; this.j = j; } A() { } } class B extends A { int l, m; B() { } B(int l, int m) { this.l = l;...
Burglary asked 22/9, 2012 at 7:34

5

Solved

Consider the following from Effective Java Item 11 (Override clone judiciously) where Josh Bloch is explaining what is wrong with the clone() contract . There are a number of problems with this ...
Evers asked 18/7, 2012 at 11:56

2

Solved

The Java specification for the java.lang.Cloneable interface defines itself as signifying that any object that extends it also has implemented the clone() method that rests dormant within java.lang...
Zoes asked 2/4, 2012 at 18:29

3

Solved

The following compiles fine: Object o = new Object(); System.out.println(o instanceof Cloneable); But this doesn't: String s = new String(); System.out.println(s instanceof Cloneable); A ...
Tenacious asked 31/3, 2010 at 8:10

2

Solved

In terms of "best practices", which methodology is preferred for creating a "deep copy" of an object?
Post asked 27/12, 2011 at 23:48

1

Solved

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 imp...
Numen asked 30/8, 2011 at 18:46

5

Solved

Java provides java.io.Serializable and java.lang.Cloneable in his standard library (and special support for it in the language and the JVM) for tasks around deserializing/serializing/cloning. Has ...
Arri asked 11/6, 2011 at 19:7

2

Solved

I am using an inner class that is a subclass of a HashMap. I have a String as the key and double[] as the values. I store about 200 doubles per double[]. I should be using around 700 MB to sto...
Gothard asked 19/4, 2011 at 17:37

5

Solved

I'm maintaing an older Java code base (jvm 1.4) that seems to use cloning as an alternative to object instantiation, I'm guessing as a performance optimization. Here's a contrived example: public ...
Soapbox asked 19/3, 2009 at 17:7

3

Solved

I have some code that performs a deep copy using Object.clone, but I'm trying to rewrite it using the more "acceptable" copy constructor technique. Below are two simple examples of what I'm trying ...
Pustule asked 16/11, 2010 at 21:56

4

Solved

Can you explain to me why I should inherit from ICloneable and implement the Clone() method? If I want to do a deep copy, can't I just implement my method? Let's say MyClone()? Why should I inher...
Beckerman asked 30/3, 2009 at 22:1

4

Solved

In Effective Java, the author states that: If a class implements Cloneable, Object's clone method returns a field-by-field copy of the object; otherwise it throws CloneNotSupportedException....
Codee asked 23/5, 2010 at 0:58

7

Solved

If a Java class implements the Serializable interface but does not have a public clone() method, it is usually possible to create a deep copy like this: class CloneHelper { @SuppressWarnings("unc...
Oilstone asked 24/1, 2010 at 18:36

5

Solved

Why wasn't the .clone() method specified in the java.lang.Cloneable interface ?
Tzong asked 2/4, 2009 at 11:47

© 2022 - 2024 — McMap. All rights reserved.