Java: Lazy Initializing Singleton

前端 未结 5 653
情书的邮戳
情书的邮戳 2020-12-10 16:14

The pattern to create singletons seems to be something like:

public class Singleton {
    private static final Singleton instance = new Singleton();
    priv         


        
5条回答
  •  温柔的废话
    2020-12-10 16:55

    You could use the Factory pattern to create the singleton, and switch implementations depending on evironment.

    Or, avoid using the singleton pattern, and use Dependency Injection instead.

提交回复
热议问题