ジェネリックでコンパイルに問題があります。 asInstanceOf
を使用すると、コードは正常にコンパイルされます。私はasInstanceOf
を取り除きたいです。scala - GenericsでasInstanceOfを使用する
asInstanceOf
の使用に関する他の質問がありましたが、私は助けませんでした。
trait RoundRobin[R <: Resource, F[_] <: mutable.ListBuffer[_]] {
self: RoundRobin[R, F] =>
// some public functions
private def overrideMutableResourceList(original: F[R], updated: F[R]): F[R] = {
val tempPool = original.asInstanceOf[mutable.ListBuffer[R]]
original.indices.foreach(i => {
val e = updated(i).asInstanceOf[R]
tempPool.update(i, e)
})
tempPool.asInstanceOf[F[R]]
}
私はtempPool.asInstanceOf[F[R]]
からasInstanceOf
を削除すると、私はこの問題は、この問題の原因は何original.asInstanceOf[mutable.ListBuffer[R]]
- ラインのためにもなりますか?
[error] /Users/...../RoundRobin.scala:108: type mismatch; [error] found : tempPool.type (with underlying type scala.collection.mutable.ListBuffer[R]) [error] required: F[R] [error] tempPool [error] ^ [error] one error found [error] (clustering/compile:compileIncremental) Compilation failed [error] Total time: 3 s, completed Oct 3, 2017 2:53:34 AM
以下のエラーが出ますか
asInstanceOf
の使用を避けるにはどうすればよいですか?
おかげ