I accidentally stumbled on this the other day. If...
# announcements
r
I accidentally stumbled on this the other day. If my parameter is defined as a function that takes 3 parameters:
Copy code
class MyClass(private val getString: (Context, Int, Array<String>) -> String)
I can call it with a lambda as such:
Copy code
MyClass { context, resId, formatArgs -> context.getString(resId, formatArgs) }
But I can also use a method reference for the first parameter and if the signature matches the second and third parameter.
Copy code
MyClass(Context::getString)
This is really cool. Is there a specific page on the docs where I can read more about this? I would love to learn more but my google-fu is failing me on this topic.
f
It's somewhere on the page about lambdas, but yeah I don't think it's super obvious when you're trying to search for it : https://kotlinlang.org/docs/reference/lambdas.html#instantiating-a-function-type
r
Thanks! I’ll read up on both of those