饿汉式
class Single
{
private static final Single s = new Single();
private Single (){}
public static Single getInstance()
{
return s;
}
}
懒汉式
class Single
{
private static Single s = null;
private Single(){}
public static Single getInstance()
{
if(s == null)
{
synchronized(Single.class)
{
if(s == null)
s = new Single();
}
}
return s;
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。