i
why?
m
Can you please make your example compilable?
Anyway, my guess is that it's because
listener
is a local variable inside
method
.
i
so should work?
if I do it as instance variable
m
Probably. But I really have no idea, because your example makes no sense at all.
i
in Java we used to use interfaces to communicate between fragments/activities
I cannot do the same thing in Kotlin
m
This seems to have nothing to do with interfaces vs lambdas. Your
listener
is just defined in the wrong scope.
i
I want to launch some data to a Fragment when get executed at a certain point to another activity
m
You need to make a compilable example if you want us to be able to help you.
i
OK, you mean a git repository?
m
No, just edit your first post. The code snippet you posted doesn't compile.
i
ah i get
done it:)
r
This works:
Copy code
fun main() {
    val myFoo = Foo()
    myFoo.call = { println("hello") }
    
    myFoo.call?.invoke()
}

class Foo(var call: (() -> Unit)? = null)