/***
*饿汉式|
/********
class Singleton{ public static Singleton s = new Singleton(); private Singleton(){} public static Singleton getInstance(){ return s; } }
/***
*懒汉式|
/********
class Singleton2{ private static Singleton2 s; private Singleton2(){} public static Singleton2 getInstance(){ if( s == null){ s = new Singleton2(); } return s; } }
原文:https://www.cnblogs.com/bigdatayun/p/12567224.html