• 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

Is there any impacts when implements the Cloneable interface?

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a class which are referred in many places and contain different data types of variables.
For my new requirement, i want to make the copy the that object.
for that reason i implements the clonable interface and make the clone of that object.
I do not have any compiler error.
however, i am thinking whether it will have any impact where this class file referred.

Regards,
Ganesan
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i am thinking whether it will have any impact where this class file referred.


I don't understand what you're asking; can you rephrase what your concern is?
 
Ganesan Ramakrishnan
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

Very simple, some of the existing classes referring the class where i implements the clonable interface.
Existing class will have any issue due to implementing the clonable interface.

Regards,
Ganesan
 
Rancher
Posts: 1044
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to shoot yourself in the foot you can.

I mean it is conceivable to write the referring code that turning a given class Cloneable disturbs it. For example there are two classes: A and B, and A is Cloneable, B is not. A method gets a reference to an object of the type A or B. Now if it decides whether the actual type is A or B based on whether the given object is an instance of Cloneable or not, this behavior would be disturbed by making the other type Cloneable too.

It is an admittedly contrived (and bad) example.
 
Bartender
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have a class which are referred in many places and contain different data types of variables.
For my new requirement, i want to make the copy the that object.
for that reason i implements the clonable interface and make the clone of that object.
I do not have any compiler error.
however, i am thinking whether it will have any impact where this class file referred.


If your question is "will changing an existing class by having it implement Cloneable break existing code which uses this class" then the answer is it depends on what your other code does. Ivan's example, whilst a little contrived, does show that existing code may break if you are relying on that class to not implement Cloneable.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic