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

Scala中的方括号(私有[…])的私有范围

发布时间:2020-12-16 09:35:17 所属栏目:安全 来源:网络整理
导读:在浏览Gatling源代码时,我遇到了以下语法: private[http] def build = { // ...} 方括号内的语法是什么? 当我在IDE中点击它,它是一个完全限定的包(com.excilys.ebi.gatling.http)的别名,但我找不到别名的定义。 解决方法 见 the scala reference,具体
在浏览Gatling源代码时,我遇到了以下语法:

private[http] def build = {
  // ...
}

方括号内的语法是什么?

当我在IDE中点击它,它是一个完全限定的包(com.excilys.ebi.gatling.http)的别名,但我找不到别名的定义。

解决方法

见 the scala reference,具体是第5.2章。一些摘录:

The private modi?er can be used with any de?nition or declaration in a template. Such members can be accessed only from within the directly enclosing template and its companion module or companion class (§5.4). They are
not inherited by subclasses and they may not override de?nitions in parent
classes.

The modi?er can be quali?ed with an identi?er C (e.g. private[C]) that must denote a class or package enclosing the de?nition. Members labeled with such a modi?er are accessible respectively only from code inside the package C or only from code inside the class C and its companion module (§5.4). Such members are also inherited only from templates inside C.

(编辑:李大同)

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

    推荐文章
      热点阅读