【发布时间】:2018-10-20 23:48:11
【问题描述】:
谁能帮我理解下面的代码有什么问题?
case class Point(x: Double, y: Double)
def centroid(points: IndexedSeq[Point]): Point = {
val x = points.reduce(_.x + _.x)
val y = points.reduce(_.y + _.y)
val len = points.length
Point(x/len, y/len)
}
运行时出现错误:
Error:(10, 30) type mismatch;
found : Double
required: A$A145.this.Point
val x = points.reduce(_.x + _.x)
^
【问题讨论】:
标签: scala reduce type-mismatch