最简单 - 单例模式

111 阅读1分钟
public class Person {
    // Person 引用
    private static Person p = null;

    static {
        if (p == null) {
            p = new Person();
        }
    }

    /**
     *单例模式获取Person对象. 
     * @return
     */
    public static Person getInstance(){
        return p;
    }  
    ​

}

转载自: 简书 - 低至一折起

文章:www.jianshu.com/p/37b9c4554…