This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes ?(cloning)  from a newbie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "?(cloning)  from a newbie" Watch "?(cloning)  from a newbie" New topic
Author

?(cloning) from a newbie

Panday Manako
Ranch Hand

Joined: Mar 29, 2001
Posts: 80
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

Joined: Feb 22, 2001
Posts: 104
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ?(cloning) from a newbie
 
It's not a secret anymore!