As run is a function that takes a lambda with a receiver (kotlin reference) in the block that is given to run this refers to the receiver, which is in your example myObject.
Therefore you need to use a qualified this-expression to refer to the enclosing MyClass-instance. As stated in the comments you need to change your code like this:
class MyClass : MyCallback {
...
fun myMethod() {
val myObject = MyObject()
myObject.run {
setCallback(this@MyClass) // <-- qualified this
}
}
override fun onMyCallback() {
// Do something
}
}
If you want to avoid labels you have to replace the run function. A possible alternative is also which instead of using a lambda with receiver gets the object as parameter:
class MyClass : MyCallback {
...
fun myMethod() {
val myObject = MyObject()
myObject.also { obj ->
//lambda without receiver, this refers to the enclosing instance of MyClass
setCallback(this)
}
}
override fun onMyCallback() {
// Do something
}
}