简体   繁体   English

哪个可见性修饰符的可见性较低:受保护的还是内部的?

[英]Which visibility modifier has lesser visibility: Protected or Internal?

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

protected means that the member has the same visibility as one marked as private, but that it is also visible in subclasses. protected 表示该成员与标记为私有的成员具有相同的可见性,但它在子类中也是可见的。

internal means that any client inside this module who sees the declaring class sees its internal members. internal 意味着该模块内的任何客户端看到声明的 class 都会看到其内部成员。

They aren't comparable;它们没有可比性; neither is more permissive than the other.两者都不比另一个更宽容。

A subclass in another module will see protected members, but not internal .另一个模块中的子类将看到protected的成员,但看不到internal

An unrelated class in the same module will see internal members, but not protected .同一模块中不相关的 class 将看到internal成员,但不受protected

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM