哪种可见性修饰符的可见度较小:受保护还是内部?
哪种可见性修饰符更允许:受保护或内部?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
受保护意味着该成员具有与私人标记的成员相同的可见性,但在子类中也可见。
内部意味着该模块中看到声明类的任何客户都会看到其内部成员。
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.
他们不可比拟;都不是宽容的。
另一个模块中的一个子类将看到
受保护的
成员,而不是内部
。同一模块中的无关类将看到
内部
成员,但不受保护
。They aren't comparable; neither is more permissive than the other.
A subclass in another module will see
protected
members, but notinternal
.An unrelated class in the same module will see
internal
members, but notprotected
.