加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 为什么我允许方法访问比类访问更少限制?

发布时间:2020-12-14 05:43:32 所属栏目:百科 来源:网络整理
导读:为什么编译? internal class A { public func f() { }} 我期望f的“公共”修饰符被禁止,因为它的封闭类是内部的. 允许这种情况的一个动机在 SE-0025: Scoped Access Level(强调我的)中提到: The compiler should not warn when a broader level of access
为什么编译?
internal class A {

    public func f() {

    }
}

我期望f的“公共”修饰符被禁止,因为它的封闭类是内部的.

允许这种情况的一个动机在 SE-0025: Scoped Access Level(强调我的)中提到:

The compiler should not warn when a broader level of access control is used within a type with more restrictive access,such as internal within a private type. This allows the owner of the type to design the access they would use were they to make the type more widely accessible. (The members still cannot be accessed outside the enclosing lexical scope because the type itself is still restricted,i.e. outside code will never encounter a value of that type.)

因此,虽然它不会改变成员的可访问性,但如果封闭类型具有更广泛的访问级别,它允许开发人员传达他们认为给定成员应具有的访问级别 – 例如,这可能对当前具有的API有用.计划在未来版本中公开的内部类型.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读