5

I am wondering what it means to declare private[this] in an object definition? It makes sense to me in a class definition, but in object?

as in:

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

what difference does it have compare to:

object Test {
  private val t: Int = 5
}
kiritsuku
  • 52,365
  • 18
  • 112
  • 133
user776635
  • 821
  • 3
  • 8
  • 13

1 Answers1

10

It is significant when the object is a companion object of a class. In that case the member that is declared private[this] may be accessed by the object but not instances of the corresponding class.

sellmerfud
  • 330
  • 2
  • 10