How to access "overridden" inner class in Scala?

Posted by doom2.wad on Stack Overflow See other posts from Stack Overflow or by doom2.wad
Published on 2010-03-12T23:31:29Z Indexed on 2010/03/12 23:37 UTC
Read the original article Hit count: 415

Filed under:
|
|
|

I have two traits, one extending the other, each with an inner class, one extending the other, with the same names:

trait A {
    class X {
        def x() = doSomething()
    }
}

trait B extends A {
    class X extends super.X {
        override def x() = doSomethingElse()
    }
}

class C extends B {
    val x = new X() // here B.X is instantiated
    val y = new A.X() // does not compile
    val z = new A.this.X() // does not compile
}

How do I access A.X class in the C class's body? Renaming B.X not to hide A.X is not a preferred way.

To make things a bit complicated, in the situation I have encountered this problem the traits have type parameters (not shown in this example).

© Stack Overflow or respective owner

Related posts about scala

Related posts about override