I.e. ```interface MySomething{ fun hello() } v...
# announcements
p
I.e.
Copy code
interface  MySomething{
  fun hello()
}

val a = object : MySomething{
  override fun hello() {
    GlobalScope.launch {
      doSomethingWithMySomething(this) <<--
    }
  }
}

fun doSomethingWithMySomething(something : MySomething){
  
}
n
Use
this@object
, eg
this@MySomething
p
nwh  [8:21 PM]
Use
this@object
, eg
this@MySomething
That doesn't work
I know I can workaround be writing sth like
val me = this
as the first statement of the hello body
d
this@functionName
- receiver
this@declaringClassName
- instance
p
I know how this stuff works in general, how does it work in this case? @Dico
n
Yeah I see what you mean, this is a strange case indeed
d
Ah, the anonymous class has no compile time name thinking
as a workaround you can do
private fun me() = this
and call it
p
I know 🤷‍♂️
d
or the thing you suggested yourself
r
I guess you cannot reference with a name/label to an anonymous object. Give the object a name (instead of using a val) and you are good to go:
Copy code
object a : MySomething {
    override fun hello() {
        launch {
            doSomethingWithMySomething(a)
        }
    }
}