Remove “this” callback in kotlin

后端 未结 2 1954
谎友^
谎友^ 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:46

    You need to use a full object expression syntax to refer to be able to refer to the instance itself:

    private val myCallback = object: SomeInterfaceType() {
        override fun onSomeEvent() {
            if (it.something) {
                someObject.removeListener(this)
            }
        }
    }
    

提交回复
热议问题