What is the difference between
class Test {
private[this] val foo = 0
}
vs
class Test {
private val foo = 0
}
What all can go inside the []
? Also, what should I search for when I want to look up the specs of this? I tried Googling various combinations of "scala access modifier arguments/parametrized scala access modifier" and nothing came up.
The first one is private for instance class, second is for class. If you use second version you have access from another instance of Test class (it's usefull for
equals
method or similiar).In The Scala Language Specification it is defined as "access modifier" and "access qualifier" (see BNF in §5.2).
You can put class name, package name or
this
there. Here is a relevant quote from language specs that explains this (see §5.2 for more details):