Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

private[this] in object definition

Tags:

scala

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
}
like image 257
user776635 Avatar asked Mar 25 '13 15:03

user776635


1 Answers

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.

like image 148
sellmerfud Avatar answered Sep 30 '22 13:09

sellmerfud