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

访问修饰符的Scala参数?

发布时间:2020-12-16 09:54:00 所属栏目:安全 来源:网络整理
导读:有什么区别 class Test { private[this] val foo = 0} VS class Test { private val foo = 0} 什么都可以进入[]?另外,当我想查看其中的规格时,我应该搜索什么?我尝试使用Google搜索“scala访问修饰符参数/参数化scala访问修饰符”的各种组合,并没有出现任
有什么区别

class Test {
  private[this] val foo = 0
}

VS

class Test {
  private val foo = 0
}

什么都可以进入[]?另外,当我想查看其中的规格时,我应该搜索什么?我尝试使用Google搜索“scala访问修饰符参数/参数化scala访问修饰符”的各种组合,并没有出现任何问题.

解决方法

what should I search for when I want to look up the specs of this?

在The Scala Language Specification中,它被定义为“访问修饰符”和“访问限定符”(参见§5.2中的BNF).

What is the difference between

What all can go inside the []?

你可以在那里放置类名,包名或.以下是语言规范的相关引用,解释了这一点(更多细节请参见§5.2):

The modifier can be qualified with an identifier C (e.g. private[C ]) that must
denote a class or package enclosing the definition. Members labeled with
such a modifier are accessible respectively only from code inside the package
C or only from code inside the class C and its companion module (§5.4).

An different form of qualification is private[this]. A member M marked with this modifier is called object-protected; it can be accessed only from within the object in which it is defined. That is,a selection p.M is only legal if the prefix is this or O.this,for some class O enclosing the reference. In addition,the restrictions for unqualified private apply.

(编辑:李大同)

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

    推荐文章
      热点阅读