Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala:类型不匹配_Scala - Fatal编程技术网

Scala:类型不匹配

Scala:类型不匹配,scala,Scala,我花了大量的时间来解决以下问题: rmseList是双打的列表 val rmseList = List(Double) var tempRMSE : Double = 0.0; for(rmse <- rmseList) { val idx = rmseList.indexOf(rmse) + 1 tempRMSE = rmse } 您可能已将Double的伴生对象放入列表中,而不是实际将Double放入其中。下面是一个例子: scala> val xs = List(D

我花了大量的时间来解决以下问题:

rmseList是双打的列表

val rmseList = List(Double)

var tempRMSE : Double = 0.0;
for(rmse <- rmseList) {
  val idx = rmseList.indexOf(rmse) + 1
  tempRMSE = rmse
}

您可能已将
Double
的伴生对象放入列表中,而不是实际将Double放入其中。下面是一个例子:

scala> val xs = List(Double)
xs: List[Double.type] = List(object scala.Double)

scala> var d: Double = 0
d: Double = 0.0

scala> for (x <- xs) { d = x }
<console>:10: error: type mismatch;
 found   : Double.type
 required: Double
              for (x <- xs) { d = x }
scala>val xs=List(双精度)
xs:List[Double.type]=List(对象scala.Double)
scala>vard:Double=0
d:Double=0.0

scala>for(x)什么是
rmseList
?这实际上与
rmseList.last
不一样吗?这个循环在编写时毫无意义。
scala> val xs = List(Double)
xs: List[Double.type] = List(object scala.Double)

scala> var d: Double = 0
d: Double = 0.0

scala> for (x <- xs) { d = x }
<console>:10: error: type mismatch;
 found   : Double.type
 required: Double
              for (x <- xs) { d = x }