class Single
{
private static final Single S = new Single();
Single(){}
public static Single getInstance()
{
s = new Single();
return s;
}
}
class Single2
{
private static Single2 s = null;
private Single2(){}
public static Single2 getInstance()
{
if(s ==null)
s = new Single2();
return s ;
}
}
第一个代码是不是说final修饰了一个s对象,不能再在方法中定义s对象了。。
再帮忙解释下第二个代码。谢谢了 |