Remove “this” callback in kotlin

后端 未结 2 1950
谎友^
谎友^ 2021-01-18 18:55

I\'m a bit kotlin newbie and I\'m trying to remove the callback instance inside the callback itself.

What I\'m trying to achieve it\'s something similar to the follo

2条回答
  •  没有蜡笔的小新
    2021-01-18 19:41

    There's also a workaround: wrap the reference to myCallback into a lambda passed to a function that calls it (e.g. run { ... }):

    private val myCallback: SomeInterfaceType = SomeInterfaceType {
       if (it.something) {
            someObject.removeListener(run { myCallback })
       }
    }
    

提交回复
热议问题