You can use any element within the available scope, that is, parameters, properties and constructor functions. You can even use other lazy properties, which can sometimes be quite useful. Here are all three options in one piece of code.
abstract class Class<V>(viewInterface: V) { private val anotherViewInterface: V by lazy { createViewInterface() } val presenter1 by lazy { initializePresenter(viewInterface) } val presenter2 by lazy { initializePresenter(anotherViewInterface) } val presenter3 by lazy { initializePresenter(createViewInterface()) } abstract fun initializePresenter(viewInterface: V): T private fun createViewInterface(): V { return /* something */ } }
Any functions and properties of the top level may also be used.
Michael
source share