Is there a way to delegate an interface by a priva...
# random
v
Is there a way to delegate an interface by a private val instead of a constructor param? in a way that lets me access the delegate object in override functions my current options seem to be: 1. Use a default param - but I would really like to not allow
pool
to be specified externally
Copy code
class BitmapPool(size: Size, pool: Pool<Bitmap> = SynchronizedPool(SYNC_BUFFER_SIZE)) : Pool<Bitmap> by pool { ... }
2. initialize the delegate anonymously - but then I can't reference the delegate when overriding functions in the interface like
super
but not
Copy code
class BitmapPool(size: Size) : Pool<Bitmap> by SynchronizedPool(SYNC_BUFFER_SIZE) { ... }
a
You could make the primary constructor private, and then have a secondary constructor without delegate parameters. Default params/Weird companion object initializers have been the main ways i’ve found of doing it (aside from a compiler plugin intrinsic which is just too much hassle lol)
👍 1
v
ah that's a good idea (second constructor)
e
also you may be interested in https://youtrack.jetbrains.com/issue/KT-2747 or related tickets
👀 2
a
That would be really nice to have
Wish that you were also able to refer to
this
even if its somewhat unsafe