Scala Language Scope A private package-specific scope


Example

You can specify a package where the private value can be accessed.

package com.example {
  class FooClass {
    private val x = "foo"
    private[example] val y = "bar"
  }
  class BarClass {
    val f = new FooClass
    f.x // <- Will not compile
    f.y // <- Will compile
  }
}