gpt4 book ai didi

java - 无法在 Java 子类中访问 Parent Kotlin 类的 protected 成员变量

转载 作者:行者123 更新时间:2023-12-02 12:57:19 26 4
gpt4 key购买 nike

abstract class Parent {

protected var name : String

}

class Child extends Parent {

private void childMethod() {
name = "child";
}
}

在子类中它给了我错误 name 在 x.x.x.Child 中具有私有(private)访问权限(x.x.x 是包名)

最佳答案

在 java 子类中,我们可以通过 getName() 访问父类的 protected 成员变量。
就像 getter 方法是自动生成的。
我是 Kotlin 的新手,需要更多地了解该方法是如何自动生成的。

关于java - 无法在 Java 子类中访问 Parent Kotlin 类的 protected 成员变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59868031/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com