def someA
(trait B
में) trait A
का उपयोग C#MyType
के साथ B
में किया जा सकता है? (फिर A#MyType =:= B#MyType
)केक पैटर्न और प्रकार
trait C {
type MyType
}
trait A {
self: C =>
def doSomething(s: MyType) { println(s.toString)}
}
trait B {
self: C =>
def someA: A
def myType: MyType
def action = someA.doSomething(myType)
}
// Mix part
case class Ahoy(value: String)
trait ConcreteC extends C {
type MyType = Ahoy
}
class PieceOfCake extends B with ConcreteC {
val someA = new A with ConcreteC
val myType = Ahoy("MyType")
}
यह संकलन नहीं करता है: प्रकार मेल नहीं खाता;
[error] found : B.this.MyType
[error] required: _1.MyType where val _1: A
[error] def action = someA.doSomething(myType))
ठीक है, यह संकलित करता है, लेकिन आप बी – jwinandy