Hey guys! I’m working on a back-end project where...
# language-proposals
m
Hey guys! I’m working on a back-end project where multiple services (hidden behind interfaces) can reference each other in a cycle. But I’d still like to pass the services in each other's constructors which is obviously not possible due to the cycles. So I thought it would be nice to have provide some kind of “lazy bridge” for the service interfaces. E.g. I have an interface
UserService
. I implement a class which simply forwards all methods & properties to a lazy property which in turn references the underlying base implementation. Right now one would have to do that manually for every method & property. It would be awesome if something like the following would be possible in Kotlin:
Copy code
class LazyUserService(base: Lazy<UserService>) : UserService by base
It would be even better if there is a generic way to do that, e.g.:
Copy code
class LazyInterface<interface T>(base: Lazy<T>) : T by base
What do you think?