Private [this] in object definition

I wonder what it means to declare private[this]in an object definition? Does this make sense to me in defining a class, but in an object?

how in:

object Test {
  private[this] val t: Int = 5
}

who cares:

object Test {
  private val t: Int = 5
}
+5
source share
1 answer

This is important when an object is a companion object of a class. In this case, the object declared private[this]can access the object, but not the instances of the corresponding class.

+10
source

All Articles