What do class / object / level access modifiers mean?
They mean the same as access modifiers for class / attribute members, since classes and traits can also be members of other classes. For example:
class A {
private class Foo
}
The class Foo
is available only to the class A
. If I change the modifier to private[this]
then it is called private and therefore any Foo
is only accessible to it by the parent instance A
.
Ads private
, private[this]
, protected
or protected[this]
only really makes sense within another class or traits, because it has to be private. In this case, it Foo
is closed to A
. The same goes for traits.
We also cannot have an object-object and make it private.
package com.example.foo
private[foo] class Foo
The class Foo
is now only visible to other members of the package com.example.foo
.
Do they make sense? In some cases, I'm sure it's useful to have private classes and traits inside some other object.
source to share