https://kotlinlang.org logo
#general-advice
Title
# general-advice
a

aishwaryabhishek3

04/01/2024, 12:40 PM
Hi Folks , How do I reference
this
inside SAM interface ? Pasting code as I don’t know why I am not getting option to attach Images . this@Observer gives error
'this' is not defined in this context
Copy code
val observer = Observer<T> {
        data = it
        latch.countDown()
        this@getOrAwaitValue.removeObserver(this@Observer)
    }
e

ephemient

04/01/2024, 4:01 PM
you will need to write it as an object,
Copy code
val observer = object : Observer<T> {
    override fun ???() {
        removeObserver(this)
    }
}
a

aishwaryabhishek3

04/01/2024, 4:04 PM
That sucks 😕 , what is the reason we cannot use this inside SAM ? Seems completely possible.
e

ephemient

04/01/2024, 4:05 PM
lambdas do not have identity