Skip to content

Commit 14e5cbc

Browse files
committed
fix bugs in Singleton implementation
1 parent 498e84e commit 14e5cbc

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

code/Coding-Interviews/src/com/todorex/offer2/Singleton3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static Singleton3 getSingleton() {
3232
if (singleton == null) {
3333
synchronized (Singleton3.class) {
3434
if (singleton == null) {
35-
return new Singleton3();
35+
singleton = new Singleton3();
3636
}
3737
}
3838
}

notes/实现Singleton模式.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public class Singleton3 {
159159
if (singleton == null) {
160160
synchronized (Singleton3.class) {
161161
if (singleton == null) {
162-
return new Singleton3();
162+
singleton = new Singleton3();
163163
}
164164
}
165165
}

0 commit comments

Comments
 (0)