本帖最后由 陈君 于 2014-8-10 20:21 编辑
下面先说下毕老师的写法:
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;
}
}
我觉得我这样写的话会更好吧:
- class Single
- {
- private static Single s=null;
- private Single(){}
- public static Single getInstance()
- {
- if(s==null)
- {
- synchronized(Single.class)
- {
- s=new Single();
- }
- }
- return s;
- }
- }
复制代码
|
|