I am dealing with Cell and I have a problem because they are not covariant. Here is what I want to do:
import net.liftweb.util.Cell
trait A {}
class AA extends A {}
trait T{
val cell:Cell[A]
}
class U extends T{
val cell:Cell[AA] = //implementation
}
I have an error because AA is a descendent of A but not equal to A.
Is there a solution?
Actually, you’re mistaken. Your error is “error: overriding value cell in trait T of type Cell[AA]; method cell needs to be a stable, immutable value: def cell:Cell[AA]”.Now, while I might suggest having T take a type parameter V <: A and then having the cell() function return a Cell[V], the real problem here is not even really related to generics. In T, your ‘cell’ is a data member. In U, ‘cell’ is a function. The compiler simply wants you to choose one (and the one that works and makes sense is for it to be a function in both places, so… just change that “val cell” to “def cell” and give one of those ‘cell’ definitions an implementation, and you’re fine).
Update (now that the question has been fixed):
Alright, so, as suggested in my original answer, you’ll want trait T to take a type parameter in order to solve this, like so: