• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there any impacts when implements the Cloneable interface?  RSS feed

 
Ganesan Ramakrishnan
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • 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
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!