I'm in a situation where I have a need to mix in a trait defined in another package. To assist with testing, a protected method in this trait is package qualified. Here is an example:
package A {
trait X {
protected[A] def method(arg: Int)
}
}
package B {
class Y extends A.X {
protected[A] def method(arg: Int) { }
}
}
Compiling this with scalac 2.9.1 yields:
test.scala:9: error: A is not an enclosing class
protected[A] def method(arg: Int) { }
Changing the "protected[A]" in class Y to any other access modifier results in this:
test.scala:9: error: overriding method method in trait X of type (arg: Int)Unit;
method method has weaker access privileges; it should be at least protected[A]
override protected def method(arg: Int) { }
My question is this: Assuming the definition of trait X can not change, is there any change to class Y that would allow it to extend trait X? (while retaining some level of 'protected' access)
If this is not possible, are there any other recommended design strategies to work around this? (other than making 'method' public)