物件私有範圍

限制最嚴格的範圍是 “物件 - 私有” 範圍,它只允許從物件的同一例項訪問該值。

class FooClass {
  private[this] val x = "foo"
  def aFoo(otherFoo: FooClass) = {
    otherFoo.x // <- This will not compile, accessing x outside the object instance
  }
}