简单粗暴。
/**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
fun main() {
println("Hello, world!!!")
Singleton.singletonTest()
}
object Singleton {//用object 表明这是个单例类,就可以了
fun singletonTest() {
println("singletonTest is called.")
}
}
本文展示了如何在Kotlin中使用`object`关键字创建一个单例类SingletonTest,通过singletonTest()方法演示其功能。

被折叠的 条评论
为什么被折叠?



