饿汉式 懒汉式饿汉式classSingleton{privatestaticSingletoninstance=newSingleton();privateSingleton(){}staticSingletongetInstance(){returninstance;}}懒汉式classSingleton{privatestaticSingletoninstance=null;privateSingleton(){}staticSingletongetInstance(){if(instance==null)instance