文章

Kotlin 单例模式推荐写法

1
2
3
4
5
6
7
8
9
10
11
12
class Singleton private constructor(){
  companion object {

    fun get() : Singleton{
      return Holder.instance
    }

    private object Holder{
      val instance = Singleton()
    }
  }
}
本文由作者按照 CC BY 4.0 进行授权