Any changes on the cloned object will it reflect the original object in java? [closed]
Any changes on the cloned object will it reflect the original object?.Please anyone explain how clone() method works internally.
java
closed as too broad by karthik, Oleg Estekhin, EdChum, Alexander Vogt, Matteo Mosca Jan 20 '15 at 10:17
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
Any changes on the cloned object will it reflect the original object?.Please anyone explain how clone() method works internally.
java
closed as too broad by karthik, Oleg Estekhin, EdChum, Alexander Vogt, Matteo Mosca Jan 20 '15 at 10:17
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
stackoverflow.com/questions/869033/…
– Tirath
Jan 20 '15 at 5:16
add a comment |
Any changes on the cloned object will it reflect the original object?.Please anyone explain how clone() method works internally.
java
Any changes on the cloned object will it reflect the original object?.Please anyone explain how clone() method works internally.
java
java
asked Jan 20 '15 at 5:09
BalasubramaniBalasubramani
2222515
2222515
closed as too broad by karthik, Oleg Estekhin, EdChum, Alexander Vogt, Matteo Mosca Jan 20 '15 at 10:17
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by karthik, Oleg Estekhin, EdChum, Alexander Vogt, Matteo Mosca Jan 20 '15 at 10:17
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
stackoverflow.com/questions/869033/…
– Tirath
Jan 20 '15 at 5:16
add a comment |
1
stackoverflow.com/questions/869033/…
– Tirath
Jan 20 '15 at 5:16
1
1
stackoverflow.com/questions/869033/…
– Tirath
Jan 20 '15 at 5:16
stackoverflow.com/questions/869033/…
– Tirath
Jan 20 '15 at 5:16
add a comment |
1 Answer
1
active
oldest
votes
So cloning is about creating the copy of original object. Its dictionary meaning is : “make an identical copy of“.
By default, java cloning is ‘field by field copy’ i.e. as the Object class does not have idea about the structure of class on which clone() method will be invoked. So, JVM when called for cloning, do following things:
1) If the class has only primitive data type members then a completely new copy of the object will be created and the reference to the new object copy will be returned.
2) If the class contains members of any class type then only the object references to those members are copied and hence the member references in both the original object as well as the cloned object refer to the same object.
If you want a clone which is independent of original and making changes in clone should not affect original. then you can use the Deep cloning
Here's the complete guide: http://howtodoinjava.com/2012/11/08/a-guide-to-object-cloning-in-java/
1
Thank you Dyrandz.
– Balasubramani
Jan 20 '15 at 5:21
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
So cloning is about creating the copy of original object. Its dictionary meaning is : “make an identical copy of“.
By default, java cloning is ‘field by field copy’ i.e. as the Object class does not have idea about the structure of class on which clone() method will be invoked. So, JVM when called for cloning, do following things:
1) If the class has only primitive data type members then a completely new copy of the object will be created and the reference to the new object copy will be returned.
2) If the class contains members of any class type then only the object references to those members are copied and hence the member references in both the original object as well as the cloned object refer to the same object.
If you want a clone which is independent of original and making changes in clone should not affect original. then you can use the Deep cloning
Here's the complete guide: http://howtodoinjava.com/2012/11/08/a-guide-to-object-cloning-in-java/
1
Thank you Dyrandz.
– Balasubramani
Jan 20 '15 at 5:21
add a comment |
So cloning is about creating the copy of original object. Its dictionary meaning is : “make an identical copy of“.
By default, java cloning is ‘field by field copy’ i.e. as the Object class does not have idea about the structure of class on which clone() method will be invoked. So, JVM when called for cloning, do following things:
1) If the class has only primitive data type members then a completely new copy of the object will be created and the reference to the new object copy will be returned.
2) If the class contains members of any class type then only the object references to those members are copied and hence the member references in both the original object as well as the cloned object refer to the same object.
If you want a clone which is independent of original and making changes in clone should not affect original. then you can use the Deep cloning
Here's the complete guide: http://howtodoinjava.com/2012/11/08/a-guide-to-object-cloning-in-java/
1
Thank you Dyrandz.
– Balasubramani
Jan 20 '15 at 5:21
add a comment |
So cloning is about creating the copy of original object. Its dictionary meaning is : “make an identical copy of“.
By default, java cloning is ‘field by field copy’ i.e. as the Object class does not have idea about the structure of class on which clone() method will be invoked. So, JVM when called for cloning, do following things:
1) If the class has only primitive data type members then a completely new copy of the object will be created and the reference to the new object copy will be returned.
2) If the class contains members of any class type then only the object references to those members are copied and hence the member references in both the original object as well as the cloned object refer to the same object.
If you want a clone which is independent of original and making changes in clone should not affect original. then you can use the Deep cloning
Here's the complete guide: http://howtodoinjava.com/2012/11/08/a-guide-to-object-cloning-in-java/
So cloning is about creating the copy of original object. Its dictionary meaning is : “make an identical copy of“.
By default, java cloning is ‘field by field copy’ i.e. as the Object class does not have idea about the structure of class on which clone() method will be invoked. So, JVM when called for cloning, do following things:
1) If the class has only primitive data type members then a completely new copy of the object will be created and the reference to the new object copy will be returned.
2) If the class contains members of any class type then only the object references to those members are copied and hence the member references in both the original object as well as the cloned object refer to the same object.
If you want a clone which is independent of original and making changes in clone should not affect original. then you can use the Deep cloning
Here's the complete guide: http://howtodoinjava.com/2012/11/08/a-guide-to-object-cloning-in-java/
answered Jan 20 '15 at 5:17
Dyrandz FamadorDyrandz Famador
3,79251534
3,79251534
1
Thank you Dyrandz.
– Balasubramani
Jan 20 '15 at 5:21
add a comment |
1
Thank you Dyrandz.
– Balasubramani
Jan 20 '15 at 5:21
1
1
Thank you Dyrandz.
– Balasubramani
Jan 20 '15 at 5:21
Thank you Dyrandz.
– Balasubramani
Jan 20 '15 at 5:21
add a comment |
1
stackoverflow.com/questions/869033/…
– Tirath
Jan 20 '15 at 5:16