I've seen this answer here showing how to do thread safe lazy initialization of a static final singleton.
But what is the best solution if the class you are lazy loading isn't final? (It has some methods you want to call after creating it)
Is it safe to just put the method calls in a static block?
public class Something {
private static class LazyHolder {
public static final Something INSTANCE = new Something();
static {
INSTANCE.setValue("foo");
}
}
public static Something getInstance() {
return LazyHolder.INSTANCE;
}
}