private volatile FieldType field;
FieldType getField() {
FieldType result = field;
if (result == null) {
synchronized(this) {
result = field;
if (result == null)
field = result = computeFieldValue();
}
}
return result;
}
As we almost all know about this is the sample code for double check idiom for lazy initialization of instance field
. But i have a silly doubt here how somebody will create the singleton object of FieldType. As to call the function getField()
(which create the singleton instance) you need an instance of the class but till now you don't have the instance. I am bit confused, please let me know. Thanks!!!