/*
饿汉式:
class Single
{
private static Single s = new Single();
private Single(){}
public void Single getInstacce()
{
return s;
}
}
懒汉式:
*/
class Single
{
private static Single s = null;
private Single(){}
public static Single getInstance()
{
if(s==null)
synchronized
{
if(s==null)
s = new Single();
}
return s;
}
} |
|