单例模式
package com.war3; public class Singleton { private static final Singleton singleton = new Singleton(); private Singleton(){} public static Singleton getInstance(){ return singleton; } }
package com.war3; public class Test { public static void main(String[] args) { Singleton s1= Singleton.getInstance(); Singleton s2= Singleton.getInstance(); System.out.println(s1==s2);//true } }
posted on 2015-12-14 01:29 confirmCname 阅读(127) 评论(0) 编辑 收藏 举报