有什么区别
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.