我正在学习Kotlin。我的代码如下:
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;
}
}
但是当我更改它并尝试为如下属性提供访问器时:
var notifier: A?
get() = notifier
它不会编译错误说:接口中的属性不能有支持字段。
从此处的文档中,kotlin 接口可以提供实现,并且可以具有带有访问器的属性。为什么编译失败?
我无法理解错误。它说什么?谁能简单的解释一下?