Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created February 2, 2020 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magdamiu/2579841e55fe0f7e7ea81d19b7baef7e to your computer and use it in GitHub Desktop.
Save magdamiu/2579841e55fe0f7e7ea81d19b7baef7e to your computer and use it in GitHub Desktop.
In Kotlin by using the "object" keyword we obtain a Singletone
object TheObject {
fun hello() = "hello"
override fun toString() = "Hello, it's me, ${TheObject::class.simpleName}"
}
fun useSingletonObject() {
println(TheObject.hello()) // => hello
val someRef: Any = TheObject
println(someRef) // => Hello, it's me, TheObject
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment