Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

?(cloning) from a newbie

 
Panday Manako
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
What's the difference between cloning and assignment?
example:
int p[] = new int[10];
int p2[] = (int[])p.clone();
VS
int p[] = new int[10];
int p2[] = p;
Thanks in advance.

 
Siva Prasad
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in this case there is no difference. Its like copying the reference of one array to another.
Array Objects has their own overriden clone() method, which only does shallow copying. i.e. something like assinging the an array reference to another array reference variable.
Inorder to get your own clone behaviour, you need to write a public method clone() in your class which must call the protected clone() method inherited from Object method.
or you can implement the Cloneable interface.
Cheers
Siva
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic