Is this version of the singleton absolutely safe?

  • 0
    Can you please tell me if this version of the Singleton pattern is safe?
    Is it possible to undermine it with the help of 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;
        }
    }
    Java Anonymous, Sep 9, 2019

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!