I am learning Kotlin. My code is as follows:
interface BaseLogicDecoupler<A : BaseViewNotifier, B : BaseScreenRouter> {
var notifier: A?
var router: B?
fun attachNotifier(notifier: A?) {
this.notifier = notifier
}
fun detachNotifier() {
notifier = null;
}
fun attachRouter(router: B?) {
this.router = router
}
fun detachRouter() {
router = null;
}
}
But when I change it and try to provide an accessor for property like following :
var notifier: A?
get() = notifier
It doesn't compile with error saying : Property in interface cannot have a backing field.
From the doc here, kotlin interfaces can provide implementation and can have properties with accessors. Why does the compilation fail?
I am unable to understand the error. What does it say? Can anyone explain in simple terms?