Scala REPLからの動作がかなり変わっています。コンパニオンオブジェクトがクラスのプライベート変数にアクセスできない
の問題もなく、次のコンパイルが:
class CompanionObjectTest {
private val x = 3
}
object CompanionObjectTest {
def testMethod(y:CompanionObjectTest) = y.x + 3
}
プライベート変数は、REPLでのコンパニオンオブジェクトからアクセスしていないようです:
scala> class CompanionObjectTest {
|
| private val x = 3;
| }
defined class CompanionObjectTest
scala> object CompanionObjectTest {
|
| def testMethod(y:CompanionObjectTest) = y.x + 3
| }
<console>:9: error: value x in class CompanionObjectTest cannot be accessed in CompanionObjectTest
def testMethod(y:CompanionObjectTest) = y.x + 3
^
はなぜ起こっていることでしょうか?