Hello, I'm trying to declare an extension method i...
# getting-started
x
Hello, I'm trying to declare an extension method inside an interface and then call that method, however, this doesn't seem to work. Is this a known limitation? I couldn't find anything that mentioned this on Kotlin docs.
Copy code
interface LazyGridForm {

    fun LazyGridScope.invoke()

}

fun LazyGridScope.form(lazyGridForm: LazyGridForm) {
    lazyGridForm.invoke()
}
c
you defined
invoke()
as an extension on
LazyGridScope
so you cannot call it as a member function of
LazyGridForm
so this will work but is not what you intended.
Copy code
fun LazyGridForm.form(lazyGridScope: LazyGridScope) {
    lazyGridScope.invoke()
}
g
As a workaround you can write
Copy code
fun LazyGridScope.form(lazyGridForm: LazyGridForm) {
    with(lazyGridForm) { this@form.invoke() }
}
x
Oh that is a good workaround
Thanks