單例模式肯定使用的是 靜態構造器

[ 728 查看 / 0 回复 ]

雖然可能在形式上是寫
class SomeType()
{
    private static SomeType instance = new SomeType() ;

    private SomeType(){}
}

但其實是等效于
class SomeType()
{
    private static SomeType instance = null;

    static SomeType(){instance = new SomeType() ;}

    private SomeType(){}
}
TOP