我已阅读“双重检查锁定已损坏”声明。但我想知道如果我通过函数创建对象,可以吗?
class Foo {
private Helper helper = null;
public Helper getHelper() {
if (helper == null)
synchronized(this) {
if (helper == null)
helper = createHelper();
}
return helper;
}
private Helper createHelper() {
return new Helper();
}
// other functions and members...
}