对象私有范围

限制最严格的范围是 “对象 - 私有” 范围,它只允许从对象的同一实例访问该值。

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