The standard method for implementing a singleton design template is as follows:
public class Singleton { private static Singleton instance = new Singleton(); public static Singleton getInstance() { return instance; } private Singleton() {} }
I was wondering if it can be implemented like this:
public class Singleton { private Singleton() {} public final static Singleton INSTANCE = new Singleton(); }
and if so, which version is better?
java design-patterns
Mat.S
source share