I have a curious problem, maybe because my classes' structure is a bit complex, but anyway :
So first I have 2 abstract classes : TestAbstract1 and TestAbstract2.
- TestAbstract2 takes a type extending TestAbstract1
- TestAbstract1 declares a val named valTest of type TestAbstract2[TestAbstract1] that has to be implemented in child classes
Code :
abstract class TestAbstract1 {
val valTest: TestAbstract2[TestAbstract1]
def meth1(): List[TestAbstract1] = {
valTest.meth2()
}
}
abstract class TestAbstract2[T <: TestAbstract1] {
def meth2(): List[T] = {
List()
}
}
Then I have one object TestObject2 that extends TestAbstract2, and a basic class Test2 that extends TestAbstract1, and has to implement valTest :
class Test2 extends TestAbstract1 {
val valTest: TestAbstract2[Test2] = TestObject2
}
object TestObject2 extends TestAbstract2[Test2] { }
The problem is here : when I compile, it tells me :
[error] overriding value valTest in class TestAbstract1 of type models.test.TestAbstract2[models.test.TestAbstract1];
[error] value valTest has incompatible type
[error] val valTest: TestAbstract2[Test2] = TestObject2
I don't know what I am doing wrong, because if I think about polymorphism rules, it should be alright ...
Do you have any idea ? Or maybe even a better way of doing what I want ?
Thank you !