为什么可以';“无法访问Kotlin伴生对象中的t对象”;静态地;其他成员何时可以?

为什么可以';“无法访问Kotlin伴生对象中的t对象”;静态地;其他成员何时可以?,kotlin,Kotlin,给定一个Kotlin伴星 class A { companion object { val a = 0 fun b() = 1 object C { val d = 0 } } } fun main(args: Array<String>) { println(A.a) println(A.b()) println(A.C.d) // doesn't co

给定一个Kotlin伴星

class A {
    companion object {
        val a = 0
        fun b() = 1
        object C {
            val d = 0
        }
    }
}

fun main(args: Array<String>) {
    println(A.a)
    println(A.b())
    println(A.C.d) // doesn't compile
    println(A.Companion.C.d)
}
A类{
伴星{
val a=0
乐趣b()=1
对象C{
val d=0
}
}
}
趣味主线(args:Array){
普林顿(A.A)
println(A.b())
println(A.C.d)//不编译
println(A.C.d)
}

A
b()
不存在时,为什么需要
Companion
访问
A.C

请注意,类中定义的属性和函数与同伴对象中定义的属性和函数没有歧义,因为前者只能在类的实例上调用。但嵌套对象可以使用类名引用:

class A {
    object C {
        val d = 0
    }
}

println(A.C.d)

您可以尝试
@JvmStatic
,这是我错过的最后一部分(在这方面,对象的行为类似于嵌套类)。