首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

创设型(单例模式)

2012-11-05 
创建型(单例模式)package com.lwf.create.singletonpublic class Singleton {private Singleton(){}priva

创建型(单例模式)

package com.lwf.create.singleton;public class Singleton {private Singleton(){}private static Singleton st = new Singleton();public static Singleton getInstance(){return st;}public static void main(String[] args) {}}class LazySingleton{private LazySingleton(){}private static LazySingleton st = null;public static synchronized LazySingleton getInstance(){if(st == null)st =  new LazySingleton();return st;}}class Test{public static void main(String[] args) {Singleton st = Singleton.getInstance();LazySingleton lzSt = LazySingleton.getInstance();}}

?

热点排行