Inheriting a method protected by a package by a class in another package

I am in a situation where I need to mix the trait defined in another package. To help in testing, the protected method in this attribute has the package qualification. 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) { }
  }
}

Compilation with scalac 2.9.1 gives:

test.scala:9: error: A is not an enclosing class
    protected[A] def method(arg: Int) { }

Changing "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: if we assume that the definition of the attribute X cannot change, is there any change in the class Y that would allow it to extend the attribute X? (while maintaining some level of "secure" access)

If this is not possible, are there any other recommended development strategies to get around this? (except for creating a "method").

+5
source
1

. , ( Y ). "AdapterMethod" Y B , , , . scala 2.9.1:

package A {
  trait X {
    protected[A] def method(arg: Int)
  }

  trait PackageAdapter {
    protected[A] def method(arg: Int) { adapterMethod(arg) }

    protected def adapterMethod(arg: Int)
  }
}

package B {
  class Y extends A.X with A.PackageAdapter {
    protected[B] def adapterMethod(arg: Int) { }
  }
}

, . Y - , , X, A ( Y B ). ?

+2

All Articles