IntelliJ can autogenerate a template for a singleton class, which looks something like this:
public class A {
private static A ourInstance = new A();
public static A getInstance() {
return ourInstance;
}
private A() {
}
}
Is this implementation of singleton thread-safe? I have read about implementing thread-safe singletons through enums. I was wondering if the above implementation is thread-safe as well. As 'ourInstance' has been defined as static and initialized as a class variable, there should be just one copy of the object.