Is there any way to pass `this` to a mixin class t...
# announcements
t
Is there any way to pass
this
to a mixin class that implements an interface via delegation? (i.e.
class Class : Interface by Mixin(this)
. It's possible to pass
this
but for some reason it refers to the companion instead of the instance itself. I realize that I could just instantiate the mixin in the class body and delegate all methods manually, but that's quite annoying.
c
Unfortunately no. You can track this issue: https://youtrack.jetbrains.com/issue/KT-5870
t
Not even with some hacky trick using delegation to anonymous classes? In its current state the delegation syntax really isn't all that useful...
c
You could pass in a delegate
d
using the constructor and then add an init block like this:
init { d.initWith(this) }
The
init
block is probably the first place where you can get a reference to the instance