Jump to content

Call an object method: Difference between revisions

Added Kotlin
(Added Common Lisp)
(Added Kotlin)
Line 604:
If you have a object called <tt>x</tt> and a method called <tt>y</tt> then you can write:
<lang javascript>x.y()</lang>
 
=={{header|Kotlin}}==
Kotlin does not have static methods as such but they can be easily simulated by 'companion object' methods :
<lang scala>// version 1.0.5-2
 
class MyClass {
fun instanceMethod(s: String) = println(s)
 
companion object {
fun staticMethod(s: String) = println(s)
}
}
 
fun main(args: Array<String>) {
val mc = MyClass()
mc.instanceMethod("Hello instance world!")
MyClass.staticMethod("Hello static world!")
}</lang>
 
{{out}}
<pre>
Hello instance world!
Hello static world!
</pre>
 
=={{header|LFE}}==
9,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.