Singleton: Difference between revisions

Added Kotlin
(Added Kotlin)
Line 1,146:
 
document.write( (new Singleton()).get() );</lang>
 
=={{header|Kotlin}}==
Kotlin has built-in support for singletons via object declarations. To refer to the singleton, we simply use its name which can be any valid identifier other than a keyword:
<lang scala>// version 1.1.1
 
object Singleton {
fun speak() = println("I am a singleton")
}
 
fun main(args: Array<String>) {
Singleton.speak()
}</lang>
 
{{out}}
<pre>
I am a singleton
</pre>
 
=={{header|Lasso}}==
9,490

edits