I came across this type mismatch that I don't understand:
error: type mismatch;
found : org.fluentlenium.core.domain.FluentList[_<:org.fluentlenium.core.domain.FluentWebElement]
required: org.fluentlenium.core.domain.FluentList[?0(in value $anonfun)] where type ?0(in value $anonfun) <: org.fluentlenium.core.domain.FluentWebElement
Note: org.fluentlenium.core.domain.FluentWebElement >: ?0, but Java-defined class FluentList is invariant in type E.
You may wish to investigate a wildcard type such as `_ >: ?0`. (SLS 3.2.10)
Indeed, it is precised that the "found" value is of type:
org.fluentlenium.core.domain.FluentList[_<:org.fluentlenium.core.domain.FluentWebElement]
=> variant type parameter
I couldn't represent a situation like this, where a "found" value is a variant type parameter. I tried this simple snippet code:
public class CarList<E extends Car> implements Collection<E> { // written in Java
//overriden methods from Collection here
}
public class Car{} // written in Java
public Ferrari extends Car{} //written in Java
object Main extends App {
val carList: CarList[Car] = new CarList[Car]
val l: CarList[Ferrari] = carList
}
Compilation Error occuring is very similar:
error: type mismatch;
found : app.CarList[app.Car] //but in this case, logically it's an invariant type: Car
required: app.CarList[app.Ferrari]
Note: app.Car >: app.Ferrari, but Java-defined class CarList is invariant in type E.
You may wish to investigate a wildcard type such as `_ >: app.Ferrari`. (SLS 3.2.10)
val l: CarList[Ferrari] = carList
^
How to modify my code snippet to end up exactly with:
- the same kind of error than
FluentList
's one (precising a variant type parameter in the "found" value):
found : app.CarList[_ :> app.Car]
- with the same advice from compiler:
You may wish to investigate a wildcard type such as _ >:
so that I can figure out what might be the origin of the issue?