Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
The class will need to implement the clone() mehod as below:
public class Singleton {
private static final Singleton singleton = new Singleton();
private Singleton() { }
public static Singleton getInstance(){
return singleton;
}
@Override
protected Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException("Cloning of this class is not allowed");
}
}
If your class which is based on the Singleton pattern does not implement the Cloneable interface then the clone() method cannot be called on that object.