I want to use Kotlin delegation but I don't want to create the delgate outside the delegator. All the samples on delegation all look like this:
interface Worker {
fun doWork()
}
class Supervisor(workerDelegate: Worker) : Worker by workerDelegate {
}
class Delegate : Worker {
override fun doWork() {
// actual work
}
}
fun main() {
val delegate = Delegate()
val supervisor = Supervisor(delegate)
supervisor.doWork() // delegates to delegate
}
But I want to create the Delegate
inside the Supervisor
. Something like this:
class Supervisor : Worker by workerDelegate {
init {
val workerDelegate = Delegate()
}
}
Is something like this possible?