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,967
  • 18
  • 114
  • 136
user776635
  • 861
  • 3
  • 9
  • 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
  • 340
  • 2
  • 10