Java-04-单态模式

class A

{

  private static final A p =new A();

  private A()

  {

    ...

  }

  public static A getP()

  {

    return p;

  }

}

public class Proj

{

  public static void main(String[] args)

  {

    A p=null;

    p=A.getP();  //p获得类A的唯一实例的引用

  }

}

原文地址:https://www.cnblogs.com/georgethrax/p/3674352.html