seetharaman venkatasamy wrote:Singleton1 is not implemented Clonable interface
Rakesh s Verma wrote:
seetharaman venkatasamy wrote:Singleton1 is not implemented Clonable interface
Is that mandatory?
Rakesh s Verma wrote:
We can always access other methods of Object class without that kind of obligation!!!
So why in the case of clone() method ?
SCJP || SCWCD
sachin verma wrote:it is a matter of confusion for me as well. can anybody elaborate it..
Rakesh s Verma wrote:As suggested by you guys , I am changing the name as it does not work as it should be.
Rakesh s Verma wrote:
But I had my own reason as I wanted to make a singleton class.
But as far as I know my code still does not create a singleton that I am trying to.
Jaikiran Pai wrote:
Creating a singleton doesn't require any use of clone(). You haven't yet told us why you are after the clone method?
So, to be absolutely positively 100% certain that a singleton really is a singleton, we must add a clone() method of our own, and throw a CloneNotSupportedException if anyone dares try!
The restriction on the singleton is that there can be only one instance of a singleton created by the Java Virtual Machine (JVM) - by prevent direct instantiation we can ensure that developers don't create a second copy.
Jaikiran Pai wrote:By the way, that article mentions only a few ways of breaking a singleton and ways to prevent that. But there are other ways too, which can easily break the singleton semantics. I am sure a search for "singleton" in this forum will provide you enough information.
Rakesh s Verma wrote:
And it will be accessible, as my class is a subclass of Object class and protected members can be accessed in subclass regardless of the directory structure.
:
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|