• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

?(cloning) from a newbie

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic