This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Originally posted by Consta Chertakovsky: How to prevent singleton object from the object cloning. ... implement clone method with throws new UnclonableObjectexception. If any other way we have to do it?
the easiest and the normal way is to leave off "implements Cloneable". Then any caller gets a similar exception as the one supposed by you.
Making any constructor private could not keep the singleton from being cloned because clone(), if Cloneable, bypasses any constructor. This bypassing any constructor is the reason for better performance.