- class Single{
-
- private static Single s =null;
- private Single() { }
-
- public static Single getInstance(){
- if(s == null)
- s = new Single();
- return s;
- }
-
- }
- public class SingleDemo {
- public static void main(String[] agrs){
-
- Single s = null;
- s = s.getInstance();;
-
- System.out.println(s);
- }
- }
复制代码 这个单例设计模式是怎么保证对象的唯一性的啊?有什么意义?
|
|