2
我有一個類,如下Java允許通過它的孩子訪問Kotlin的基本變量,但不允許Kotlin訪問,爲什麼?
open class KotlinBase {
companion object {
const val TAG = "testing"
}
}
而作爲
class KotlinChild : KotlinBase()
它的孩子。當我試圖從一個Java類訪問標記,我既可以
public class JavaOther {
String test1 = KotlinBase.TAG; // This is okay
String test2 = KotlinChild.TAG; // This is okay
}
然而,當從Kotlin課程訪問時,我無法通過孩子訪問。
class KotlinOther {
val test1 = KotlinChild.TAG // Compile/Syntax error
val test2 = KotlinBase.TAG // This is okay
}
爲什麼不能我科特林級接入繼承的變量TAG
通過KotlinChild
?