为什么受保护的var是KProperty,而公共/私有var是KMutableProperty?

时间:2018-12-14 11:31:50

标签: kotlin

在以下每种情况下,我都有一些 mutable var属性。根据Javadocs,可变属性由KMutableProperty表示,但是在这些示例中,protected属性由KProperty类表示。为什么会这样?

class FooA {
    var publicProp: String? = null
    protected var protectedProp: String? = null
    private var privateProp: String? = null

    fun foo() {
        val a = ::publicProp
        val b = ::protectedProp
        val c = ::privateProp
    }
}

open class FooB {
    var publicProp: String? = null
    protected var protectedProp: String? = null
    private var privateProp: String? = null

    fun foo() {
        val a = ::publicProp
        val b = ::protectedProp
        val c = ::privateProp
    }
}

class Bar : FooB() {
    fun bar() {
        val a = ::publicProp
        val b = ::protectedProp
    }
}

Type hints from IDEA

0 个答案:

没有答案