单例模式

 1 public class UserService {
 2     //1.将构造方法私有化,不允许外部直接创建对象
 3     private UserService(){        
 4     }
 5     //2.创建类的唯一实例
 6     private static UserService instance=new UserService();
 7     //3.提供一个获取实例的方法
 8     public static UserService getInstance(){
 9         return instance;
10     }
11
原文地址:https://www.cnblogs.com/tongx123/p/4966780.html