Pattern(设计模式)。单例模式(Singleton):表示一个类只会生成唯一的一个对象。
1 package eameple; 2 public class SingletonTest 3 { 4 public static void main(String[] args) 5 { 6 Singleton singleton = Singleton.getInstance(); 7 Singleton singleton2 = Singleton.getInstance(); 8 9 System.out.println(singleton == singleton2); 10 } 11 } 12 class Singleton 13 { 14 private static Singleton singleton=new Singleton(); 15 16 private Singleton() 17 { 18 19 } 20 public static Singleton getInstance() 21 { 22 return singleton; 23 } 24 25 26 }
原文:http://www.cnblogs.com/daneres/p/4441290.html