Singleton 3 大要素:
1.有private static的句柄(成员变量即field)
2. constructor 必须为private
3.有public static的getInstance方法
class Solution { private static Solution instance; private Solution(){ } /** * @return: The same instance of this class every time */ public static Solution getInstance() { if(instance == null){ instance = new Solution(); } return instance; } };
浙公网安备 33010602011771号