Skip to content

Commit 71ff0de

Browse files
committed
constructor of Singleton should be private
1 parent 5fcc4e9 commit 71ff0de

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

doc/Java面试题集.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ public class Singleton {
276276
//volatile保证了:1 instance在多线程并发的可见性 2 禁止instance在操作是的指令重排序
277277
private volatile static Singleton instance;
278278

279+
private Singleton(){}
280+
279281
public static Singleton getInstance() {
280282
//第一次判空,保证不必要的同步
281283
if (instance == null) {

0 commit comments

Comments
 (0)