“private[syntax]” in Scala

自闭症网瘾萝莉.ら 提交于 2019-12-04 05:32:06

问题


What is this "private[syntax]" language feature?

/** Wraps a value `self` and provides methods related to `Show` */
final class ShowOps[F] private[syntax](val self: F)(implicit val F: Show[F]) extends Ops[F] {
  ////
  final def show: Cord = F.show(self)
  final def shows: String = F.shows(self)
  final def print: Unit = Console.print(shows)
  final def println: Unit = Console.println(shows)
  ////
}

^ Location: scalaz-series-7.3.x/core/src/main/scala/scalaz/syntax/ShowSyntax.scala


回答1:


private[packageX] means the following method/class/object/constructor is accessible only from within that package - in this case syntax is the package name, and this constructor is only accessible from other code inside syntax package.



来源:https://stackoverflow.com/questions/35929039/privatesyntax-in-scala

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!