Kotlin: how can i create a singleton using the `object` keyword?
Example:
// Trying to define a singleton
class Singleton {
fun show() {
println("This is a singleton")
}
}
Solution:
// Proper singleton using `object` keyword in Kotlin
object Singleton {
fun show() {
println("This is a singleton")
}
}
In Kotlin, singletons can be easily created using the `object` declaration, which ensures there's only one instance of the class.