Answer the question
In order to leave comments, you need to log in
Is this version of the singleton absolutely safe?
Can you please tell me if this version of the Singleton pattern is safe?
Can it be undermined by reflection, or in some other way?
public class MySingleton implements Cloneable{
private static MySingleton mySingleton = new MySingleton();
private MySingleton(){}
public static MySingleton getInstance(){
return mySingleton;
}
@Override
protected Object clone() throws CloneNotSupportedException {
return mySingleton;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question