Created
December 12, 2015 02:27
-
-
Save mindwing/332897edc5e31a99cb9d to your computer and use it in GitHub Desktop.
private 생성자에 관한 예제입니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by mindwing on 2015-12-12. | |
*/ | |
public class Singleton { | |
private static Singleton instance = new Singleton(); | |
private Singleton() { | |
} | |
public static Singleton getInstance() { | |
return instance; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by mindwing on 2015-12-12. | |
*/ | |
public class SingletonTest { | |
public static void main(String[] args) { | |
// Singleton 클래스의 생성자가 private !!! | |
// Singleton singleton = new Singleton(); | |
Singleton singleton = Singleton.getInstance(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment