Any ideas what this means?
# getting-started
y
Any ideas what this means?
l
Because your
on
function is not inline, that lambda is considered as a closure, and because closure is self-contained, it must "capture" stuff in the outer scope, and now that it's not possible to directly modify a local variable in a closure, that local is wrapped into an object with a var member for the closure to "modify".
y
oh ok
How can i fix this issue
@Loney Chou
l
either
inline
your on function or rather just ignore it
y
The thing is it is already inlined
Copy code
inline fun <reified T : Event> EvenTester.on(
    crossinline consumer: suspend Event.(T) -> Unit
): EventListener {
    return object : EventListener {
            override suspend fun onEvent(event: Event) {
                if (event is T) {
                    event.consumer(event)
                }
            }
        }
        .also { this.addEvent(it) }
}
l
Sorry for the delay. Because
consumer
is crossinline, anything inside it should be captured to be used in this
EventListener
object, so
consumer
is effectively closure. You need to ignore that "Captured..." info then. To be honest this is not a big deal.