Apex han wrote:
Upto this ok! but how to stop cloning..
I already spend so much time in searching for it...but it doesn't clarify..that's i posted my doubt..
Apex han wrote:Upto this ok!
but how to stop cloning..
himanshu.harish agrawal wrote:As correctly said by Henry the object are not by default clonable. So, if you will try to clone the object you will immediately get CloneNotSupportedException.
So, not to worry about cloning, if you do not want your class to support cloning.
But if you want then Override clone() and throw a CloneNotSupportedException.
So returning "this", thereby letting x.clone() == x, is allowed.The general intent is that, for any object x, the expression: will be true, and that the expression: will be true, but these are not absolute requirements.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Prabhat Ranjan wrote:
himanshu.harish agrawal wrote:As correctly said by Henry the object are not by default clonable. So, if you will try to clone the object you will immediately get CloneNotSupportedException.
So, not to worry about cloning, if you do not want your class to support cloning.
But if you want then Override clone() and throw a CloneNotSupportedException.
few of the objects are as default clonable like Vector.
Prabhat Ranjan wrote:that is fine, no userdefined classes are by default implements clonable.
But if i haven't overriden the clone() method and implemented Clonable Interface.
It means my class is secure no one can make copy of it, correct.
himanshu.harish agrawal wrote:
Prabhat Ranjan wrote:that is fine, no userdefined classes are by default implements clonable.
But if i haven't overriden the clone() method and implemented Clonable Interface.
It means my class is secure no one can make copy of it, correct.
If that was a question then Yes, you are safe ..![]()
Reiterating: No user defined class (whether abstract, concrete, inner, singleton, factory etc..) is by default clonable.
Thanks.
Alex Hurtt wrote:
himanshu.harish agrawal wrote:
Prabhat Ranjan wrote:that is fine, no userdefined classes are by default implements clonable.
But if i haven't overriden the clone() method and implemented Clonable Interface.
It means my class is secure no one can make copy of it, correct.
If that was a question then Yes, you are safe ..![]()
Reiterating: No user defined class (whether abstract, concrete, inner, singleton, factory etc..) is by default clonable.
Thanks.
But what if your singleton class happens extends another class that does implement Cloneable and does support cloning? Or perhaps an abstract Cloneable superclass that doesn't provide the clone() implementation? (though admittedly extending such a class as a singleton would seemingly make little sense as the author would be telling you that any concrete subclasses should be Cloneable) Your only choice then it would seem would be to override and either return 'this' or else throw the CloneNotSupportedException.
"Software development has been, is, and will remain fundamentally hard"
- Grady Booch
Lasagna is spaghetti flvored cake. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|