Hi,
Can anybody clear my confusion on the object cloning concept.
I wrote a singleton class ... then somebody told me with cloning I can get one more object. Then I started searching over the internet.
I read many articles saying to avoid cloning we need to override the Object clone() method..
but what is the need of it..
Followed this discussion -
cloning singleton object
As per the
documentation,
"Invoking Object's clone method on an instance that does not implement the Cloneable interface results in the exception CloneNotSupportedException being thrown."
Calling the clone method on an object, will result in throwing an exception at run time.
Hence, when I am writing a singleton class and not implementing Cloneable interface, there is no chance of anyone cloning this singleton object. Even though clone method comes from Object super class..
I guess, any object whose class implements this Cloneable interface is eligible for cloning.. Please clear me if I am wrong..
Thanks