jeff
02/03/2021, 3:34 AMclass A {
fun B.something() { ... }
}
something()
has two receivers, A and B, yeah?
I was hoping that would let me do this:
class B {
init {
val a = A()
a.something()
}
}
but it seems in reality I have to do this:
class B {
init {
val a = A()
with(a) {
something()
}
}
}
Is there a nicer way to get something closer to the first one?Nir
02/03/2021, 3:47 AMsomething
has a good reason to be a member of A
. Why not though simply fun something(b: B)
, and then in B
you can do a.something(this)
Nir
02/03/2021, 3:48 AMfun something(b: B) = b.run { ... }
jeff
02/03/2021, 4:00 AMthis
in constantly when it's already in scope at the call site.Nir
02/03/2021, 5:11 AMNir
02/03/2021, 5:17 AMNir
02/03/2021, 5:18 AMHanno
02/03/2021, 9:33 AM