Questions tagged [cloneable]
163 questions
2
votes
2 answers
Improving safety of Clone pattern
If one wants to implement Clone pattern in C++, he might not be sure about safety, because derived class may forget to override it:
struct A {
virtual A* Clone() const {
return new A(*this);
}
}
struct B : A {
int value;
};
int…

Nikita Petrenko
- 1,068
- 1
- 7
- 10
2
votes
2 answers
Clone an android application programmatically
There are some Android applications which allow user to clone existed application on the phone.
eg: http://fixoptimize.com/app-cloner
Can you explain how these cloners work?
Thank you.

Anh-Tuan Mai
- 1,129
- 19
- 36
2
votes
1 answer
Generic class, calling generic class with clone
I need to make a generic class with implements cloneable, and to accomplish this I needed to do a clone method of the class and another method to get this method.
The teacher passed it in the room, but is not working and giving Method error. What…

lisa15x
- 23
- 3
2
votes
2 answers
No clone method in String Class
A technical aptitude question
HashMap map = new HashMap();
String key1 = "key1";
map.put(key1, "value1");
String key2 = key1.clone();
map.put(key2, "value2");
What are the contents of the map object?
I answered it as…

Bonny Mathew
- 171
- 1
- 7
2
votes
6 answers
Cloneable behaviour
Java doc says -
The class Object does not itself
implement the interface Cloneable, so
calling the clone method on an object
whose class is Object will result in
throwing an exception at run time.
Which is why clone method in Object class…

carnot
- 101
- 1
- 3
- 9
2
votes
1 answer
Java: Is setters should make `Clone` or it's up to caller pass `new` copy?
What considered to be the best & common practice if I want to make sure that after setter is called the object cannot be modified from outside? In the code there is detailed simple self explained example, With 2 options dilemma.
//caller…

michael
- 3,835
- 14
- 53
- 90
2
votes
2 answers
why protected clone() method is not accessible using inheritance in same package
I know by inheritance all classes inherit methods from Object class.Similarly if we extends one class with other it also inherit method. Then why we can call inherited protected method from other class and not able to call inheritate method from…

Javakar
- 21
- 2
2
votes
3 answers
CXF: Cloneable classes from wsdl2java?
Is it possible to have CXF's wsdl2java emit cloneable classes? Maybe via some option or a plug-in?
What I need to do is copy by value a rather complex schema structure from one object tree to another and would rather not get/set each member value…

Bjorn Thor Jonsson
- 827
- 1
- 10
- 21
2
votes
0 answers
Cloning an object in java: org.objenesis.ObjenesisException: java.lang.NoSuchMethodException: newInstance [class java.lang.Class, int]
I am using Espresso to test my application.
I am also using the library uk.com.robust-it:cloning (Java Deep Cloning Library) version 1.9.2 to clone an object.
If I am using the application, I have no exception, but when the tests are running, I…

Cícero Moura
- 2,027
- 1
- 24
- 36
2
votes
3 answers
Question about the Cloneable interface and the exception that should be thrown
The Java documentation says:
A class implements the Cloneable
interface to indicate to the
Object.clone() method that it is
legal for that method to make a
field-for-field copy of instances of
that class.
Invoking Object's clone method…

rfgamaral
- 16,546
- 57
- 163
- 275
2
votes
0 answers
Why do I have the option to remove the throws clause here even though the interface I inherit from defined it?
The interface in question is FileVisitor, which defines this method:
FileVisitResult preVisitDirectory(T dir, BasicFileAttributes attrs)
throws IOException;
My really simple implementation is this:
public final class FailFastDeletionVisitor
…

fge
- 119,121
- 33
- 254
- 329
2
votes
2 answers
Implementing Clonable in Java
In which cases should I use this way:
public A clone() throws CloneNotSupportedException {
A clone = (A)super.clone();
clone.x= this.x;
return clone;
}
And in which cases should I use that way:
public ShiftedStack clone() throws…

Artium
- 5,147
- 8
- 39
- 60
2
votes
4 answers
Why can't I type Clone() properly?
Like any other C# programmer, I face the problem of how best to express the copying of objects.
Specifically, I have a class hierarchy in which all objects must be copyable.
It has already been discussed whether to use copy constructors (which C#…

reinierpost
- 8,425
- 1
- 38
- 70
2
votes
2 answers
how to clone a Parcel object
I want to clone a Parcel object (not parcelable).
I can't use clone() method since it is protected. I also can't call it using reflection since Parcel class doesn't implement 'clonable'
I tried to perform the solution of issue:
Create a copy of…

morang
- 151
- 2
- 10
2
votes
4 answers
super.clone() operation not works in Derived Class
This is raised because of the technical difficulties faced in my Project.
Problem:
I need to clone a Object of a Class where it extended the properties(Inheritance) from a third party library class(where we don't have access to modify its…

omega
- 592
- 2
- 5
- 21