class Singleton{
companion object{
val instance: Singleton by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED){Singleton()}
}
fun show(){
println("show")
}
}
fun main() {
Singleton.instance.show()
}
Kotlin 双重校验安全的单例模式
最新推荐文章于 2024-08-21 14:13:51 发布