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
asdf asdf
03/20/2023, 9:45 PM
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)