Suppose I have the following code:
trait Trait1 {
trait Inner {
val name = "Inner1"
}
}
trait Trait2 {
trait Inner {
val name = "Inner2"
}
}
class Foo extends Trait1 with Trait2 {
// I want Concrete1 to be a Trait1.Inner not a Trait2.Inner
class Concrete1 extends Inner
val c = new Concrete1
}
object Obj {
def main(args: Array[String]): Unit = {
val foo = new Foo
println(foo.c.name)
}
}
When I mix in Trait1
and Trait2
, referring to Inner
seems to default to the Inner
type of whichever trait I mixin second; so when I call Obj
's main
method it prints Inner2
. How can I refer to Trait1.Inner
in Foo
? All three of the following give compiler errors:
class Concrete1 extends Trait1.Inner
class Concrete1 extends Trait1$Inner
class Concrete1 extends Trait1#Inner