用java写一个单例模式
public class Singleton {
private static Singleton instance;
private Singleton() { //私有构造函数,防止外部实例化 }
public static Singleton getInstance() { if (instance == null) { instance = new Singleton(); } return instance; }
public void showMessage() { System.out.println("Hello, World!"); } }
原文地址: https://www.cveoy.top/t/topic/b76q 著作权归作者所有。请勿转载和采集!