哪种可见性修饰符的可见度较小:受保护还是内部?

发布于 2025-02-12 06:52:02 字数 446 浏览 1 评论 0原文

哪种可见性修饰符更允许:受保护或内部?

 internal var num = 18
        protected set   // throws an error at 'protected' showing: Setter visibility must be the same or less permissive than property visibility

,我也尝试了:

 protected var num = 18
        internal set   // throws an error at 'internal' showing: Setter visibility must be the same or less permissive than property visibility

Which visibility modifier is more permissive: Protected or Internal?

 internal var num = 18
        protected set   // throws an error at 'protected' showing: Setter visibility must be the same or less permissive than property visibility

And I try this also:

 protected var num = 18
        internal set   // throws an error at 'internal' showing: Setter visibility must be the same or less permissive than property visibility

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吻泪 2025-02-19 06:52:05

受保护意味着该成员具有与私人标记的成员相同的可见性,但在子类中也可见。

内部意味着该模块中看到声明类的任何客户都会看到其内部成员。

protected means that the member has the same visibility as one marked as private, but that it is also visible in subclasses.

internal means that any client inside this module who sees the declaring class sees its internal members.

岁吢 2025-02-19 06:52:04

他们不可比拟;都不是宽容的。

另一个模块中的一个子类将看到受保护的成员,而不是内部

同一模块中的无关类将看到内部成员,但不受保护

They aren't comparable; neither is more permissive than the other.

A subclass in another module will see protected members, but not internal.

An unrelated class in the same module will see internal members, but not protected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文