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
?