Protected Members of Other Instances in Scala
Posted
by
Masterofpsi
on Stack Overflow
See other posts from Stack Overflow
or by Masterofpsi
Published on 2011-01-07T01:51:53Z
Indexed on
2011/01/07
1:53 UTC
Read the original article
Hit count: 562
I just ran into a difficulty while learning Scala. I have an inheritance hierarchy that is essentially equivalent to this:
class A {
protected def myMethod() = println("myMethod() from A")
}
class B extends A {
def invokeMyMethod(a: A) = a.myMethod()
}
But trying to compile this sample, I get the error "test.scala:7: error: method myMethod cannot be accessed in A".
Coming from Java, my understanding is that protected members should be accessible at any point from a derived class, and nowhere have I seen anything that tells me that protected members in Scala are limited by instance. Does anyone have an explanation for this?
© Stack Overflow or respective owner