On Thu, Sep 20, 2012 at 10:17:02AM -0400, Michael Swierczek wrote:
> I believe Hjalmar Peters' confusion, which I share, is that
> "protected" in Scala means that the declared class, object, method,
> val, etc... can only be accessed by itself and its subclasses.
I think you're slightly confused. A protected inner class can only be
accessed by its *enclosing* class and subclasses. The Scala compiler
will enforce this constraint (although it won't be reflected in the
Java bytecode AFAIK):
class Outer {
protected class Inner
def inner() = new Inner()
}
class Related extends Outer {
def ok() = new Related().inner()
def fails() = new Outer().inner()
}
class Unrelated {
def alsoFails() = new Outer().inner()
def stillFails() = new Related().inner()