单例模式
public class Singleton {
2. private static Singleton instance;
3. private Singleton (){}
4.
5. public static Singleton getInstance() {
6. if (instance == null) {
7. instance = new Singleton();
8. }
9. return instance;
10. }
}
public class Singleton {
2. private static Singleton instance;
3. private Singleton (){}
4. public static synchronized Singleton getInstance() {
5. if (instance == null) {
6. instance = new Singleton();
7. }
8. return instance;
9. }
10.}
public class Singleton {
2. private static Singleton instance = new Singleton();
3. private Singleton (){}
4. public static Singleton getInstance() {
5. return instance;
6. }
7.}