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

前端 未结 2 2093
太阳男子
太阳男子 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 15:00

    In short: this is used for scope protection:

    • private[C] means that access is private "up to" C, where C is the corresponding package, class or singleton object.

    Same to protected[C]

    • protected[C]: access is protected "up to" C, where C is the corresponding package, class or singleton object.

提交回复
热议问题