StackOverflow 文件 Scala Language 教程 範圍 物件私有範圍 物件私有範圍 Created: November-22, 2018 限制最嚴格的範圍是 “物件 - 私有” 範圍,它只允許從物件的同一例項訪問該值。 class FooClass { private[this] val x = "foo" def aFoo(otherFoo: FooClass) = { otherFoo.x // <- This will not compile, accessing x outside the object instance } } 受保護的範圍私有包特定範圍