📜  什么是 Android 中的单例类? - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:34.643000             🧑  作者: Mango

代码示例1
private static volatile RESTService instance;
 protected RESTService(Context context) {
     super(context);
 }
 
 public static RESTService getInstance(Context context) {
 if (instance == null) {
    synchronized (RESTService.class) {
       if (instance == null) instance = new RESTService(context);
         }
     }
     return instance;
 }