We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 012da33 commit 44b6b0fCopy full SHA for 44b6b0f
1 file changed
SingletonPattern/Java/EagerlySingleton.java
@@ -0,0 +1,26 @@
1
+public class EagerlySingleton
2
+{
3
+ // Use static initiallizer, that will make instace created fast.
4
+ private static EagerlySingleton instance = new EagerlySingleton();
5
+
6
+ private EagerlySingleton()
7
+ {
8
+ }
9
10
+ // Just get the instance
11
+ public static EagerlySingleton getInstance()
12
13
+ return instance;
14
15
16
+ public static void main(String[] args)
17
18
+ EagerlySingleton singletonInstance1 = EagerlySingleton.getInstance();
19
+ EagerlySingleton singletonInstance2 = EagerlySingleton.getInstance();
20
21
+ if(singletonInstance1 == singletonInstance2)
22
23
+ System.out.println("They're the same instance");
24
25
26
+}
0 commit comments