Hi What is this feature called in Kotlin, where we...
# getting-started
d
Hi What is this feature called in Kotlin, where we call a function with :: ?
Copy code
```fun someFunction(param: (String) -> Unit) {}

class SomeClass {
    fun functionWithOneParameter(param: String) {}
}

// caller place
// what is this :: notation called?
val someClass = SomeClass()
someFunction(param = someClass::functionWithOneParameter)
p
d
Thank you
v
And just to make it clear, you are not calling the function where you reference it with
::
. 🙂
d
So we are just passing the reference and not actually calling it? Now I wonder if there is any performance difference or some other difference when reference with
::
and actually calling the function?
v
It's not so much about performance, it is simply a different use-case. You can for example give callbacks like that, that are then called on certain events and similar.
d
Got it, thanks
p
it can be thought of as syntactically cleaner, because you know for sure that you’re using another method verbatim instead of (possibly) hiding some side effect in a lambda AFAIK the performance is basically equivalent on modern JVMs, or at least not something you should really care about 99% of the time
e
the call performance is the same
the construction performance (if it's not inlined) may be different as callable references have a few additional features that lambdas don't have
s
"callable reference" 6 syllables 😬, that's probably why this is called a "tear-off" in other languages.