读书人

单例的最佳实践!

发布时间: 2013-09-10 13:42:18 作者: rapoo

单例的最佳实践!!

http://en.wikipedia.org/wiki/Singleton_pattern

public class Singleton {        // Private constructor prevents instantiation from other classes        private Singleton() { }         /**        * SingletonHolder is loaded on the first execution of Singleton.getInstance()         * or the first access to SingletonHolder.INSTANCE, not before.        */        private static class SingletonHolder {                 public static final Singleton INSTANCE = new Singleton();        }         public static Singleton getInstance() {                return SingletonHolder.INSTANCE;        }}

读书人网 >编程

热点推荐