Created
February 2, 2020 14:51
-
-
Save magdamiu/2579841e55fe0f7e7ea81d19b7baef7e to your computer and use it in GitHub Desktop.
In Kotlin by using the "object" keyword we obtain a Singletone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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