访问修饰符的Scala参数? [英] Scala parameters for access modifiers?
问题描述
What is the difference between
class Test {
private[this] val foo = 0
}
vs
class Test {
private val foo = 0
}
[]
里面有什么?另外,当我要查找此规格时应该搜索什么?我尝试了谷歌搜索 scala访问修饰符参数/参数化的scala访问修饰符的各种组合,但没有结果。
What all can go inside the []
? Also, what should I search for when I want to look up the specs of this? I tried Googling various combinations of "scala access modifier arguments/parametrized scala access modifier" and nothing came up.
推荐答案
当我要查找此规格时应该搜索什么?
what should I search for when I want to look up the specs of this?
在 Scala语言规范,它被定义为访问修饰符和访问限定符(请参见BNF §5.2)。
In The Scala Language Specification it is defined as "access modifier" and "access qualifier" (see BNF in §5.2).
What is the difference between
...有什么区别/ p>
...
所有内容都可以放入[]?
What all can go inside the []?
您可以在此处放置类名称,包名称或此
。以下是语言规范中的相关引文对此进行了解释(有关更多详细信息,请参见§5.2):
You can put class name, package name or this
there. Here is a relevant quote from language specs that explains this (see §5.2 for more details):
修饰符可以用标识符限定必须
表示包围该定义的类或包的C(例如private [C])。带有
这样修饰符的成员只能分别从
C包中的代码或仅从C类及其配套模块(第5.4节)中的代码访问。
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).
另一种形式的资格是私人[this]。用该修饰符标记为
的成员M称为对象保护的;只能从定义它的对象内的
访问它。也就是说,对于前缀为O的某些类,仅当前缀为this或O.this时,选择p.M才是合法的。除
外,还适用不合格的私人限制。
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.
这篇关于访问修饰符的Scala参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!