小编Ser*_*iuk的帖子

Kotlin无法访问受保护的抽象方法

我有以下类结构:

abstract class Abstr{
    protected abstract fun m()
}

class Child : Abstr(){
    private val subChild: Abstr = Child()

    override fun m() = subChild.m()// Error:(12, 18) Kotlin: Cannot access 'm': it is protected in 'Abstr'
}
Run Code Online (Sandbox Code Playgroud)

我有一个例外 Kotlin: Cannot access 'm': it is protected in 'Abstr'

这有点令人困惑,因为相同的结构对于java来说是合法的.

根据kotlin docs

  • protected - 仅在此类中可见+在子类中也可见;

是bug还是预期的行为?

kotlin

8
推荐指数
2
解决办法
1722
查看次数

标签 统计

kotlin ×1