理解できないこのタイプの不一致に遭遇しました:
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)
実際、「見つかった」値は次のタイプであることが正確です。
org.fluentlenium.core.domain.FluentList[_<:org.fluentlenium.core.domain.FluentWebElement]
=> バリアント型パラメータ
「見つかった」値がバリアント型パラメーターである、このような状況を表すことができませんでした。私はこの簡単なスニペットコードを試しました:
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
}
発生するコンパイルエラーは非常に似ています:
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
^
コードスニペットを変更して正確に終了する方法:
- のものと同じ種類のエラー
FluentList
(「見つかった」値のバリアント型パラメーターを正確にする):
found : app.CarList[_ :> app.Car]
- コンパイラからの同じアドバイスで:
You may wish to investigate a wildcard type such as _ >:
問題の原因が何であるかを理解できるようにするには?