Private scoping with square brackets (private[…]) in Scala

前端 未结 2 2104
太阳男子
太阳男子 2020-12-28 14:17

I\'ve come across the following syntax while looking through the Gatling source code:

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

What is the sy

2条回答
  •  粉色の甜心
    2020-12-28 14:47

    See the scala reference, specifically, chapter 5.2. Some excerpt:

    The private modifier can be used with any definition 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 definitions in parent classes.

    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). Such members are also inherited only from templates inside C.

提交回复
热议问题