• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object Clone  RSS feed

 
vaagesh Chnadra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

After Clone both the Original and cloned objects reside in same memory
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the API documentation for Object#clone() and that should enable you to answer your question.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Define "same memory". If you mean the same memory pool, then yes. If you mean the same physical memory chips, then nobody can say. If you mean the same memory address, then also nobody can say. From the Javadoc about Object.clone:
Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression: will be true, and that the expression: will be true, but these are not absolute requirements. While it is typically the case that: will be true, this is not an absolute requirement.

Usually, x.clone() != x as said there, which mean that the two objects would not have the same memory address, but it is still allowed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!