Singleton: Difference between revisions
Content added Content deleted
(Added Kotlin) |
|||
Line 1,146: | Line 1,146: | ||
document.write( (new Singleton()).get() );</lang> |
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}}== |
=={{header|Lasso}}== |