小猪来学习
2015-03-02 22:02
为什么 在 Singleton前面加上staic就可以在外部类获取实例了。
加上 static 修饰才能被外部的调用呀,
由于类不能被实例化,获取类内部的实例的方法必须为静态的。所有在 Singleton前面必须加上static。
例如:
public static Singleton getInstance() { return INSTANCE; }
模式的秘密---单例模式
74399 学习 · 108 问题