Java: Lazy Initializing Singleton
问题 The pattern to create singletons seems to be something like: public class Singleton { private static final Singleton instance = new Singleton(); private Singleton(){ } public static Singleton getInstance() { return instance; } } However my problem is how do you Unit with a class like this if the Singleton Constructor does something that is not unit test friendly e.g. calls external service , jndi lookup etc. I would think i could refactor it like: public class Singleton { private static