I was a bit surprised when i found out that private members of companion objects are visible to the class, e.g to some member function within the class.
class A {
companion object {
private val x = 5
}
fun someMemberFunction() = x // x is visible here
}
But if we have an normal object, it’s private members are not visible outside of object itself (as i expected):
class A {
object B {
private val x = 5
}
fun someMemberFunction() = B.x // x is not visible here
}
How can we argue that these two very similar concepts differ in this way?