From 7b5de89dd4dcf4df0d487218b3f5fc3510941894 Mon Sep 17 00:00:00 2001 From: Hammy Date: Mon, 14 Dec 2020 20:29:25 +0000 Subject: [PATCH] Improve Implementation of Singleton --- Design Patterns/src/singleton/SingleObject.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Design Patterns/src/singleton/SingleObject.java b/Design Patterns/src/singleton/SingleObject.java index 3939890..4f113a8 100644 --- a/Design Patterns/src/singleton/SingleObject.java +++ b/Design Patterns/src/singleton/SingleObject.java @@ -2,12 +2,15 @@ package singleton; public class SingleObject { - private static final SingleObject instance = new SingleObject(); + private static SingleObject instance = new SingleObject(); private SingleObject() { } public static SingleObject getInstance() { + if (instance == null) { + instance = new SingleObject(); + } return instance; }