【发布时间】:2014-11-29 02:17:00
【问题描述】:
我正在尝试使用 Scala 类计算两点之间的距离。但它给出了一个错误提示
类型不匹配; found : other.type (基础类型 Point) required: ?{def x: ?} 注意隐式转换不是 适用,因为它们是模棱两可的:两种方法 any2Ensuring in [A](x:A)Ensuring[A] 类型的对象 Predef 和方法 any2ArrowAssoc 在 [A](x:A)ArrowAssoc[A] 类型的对象 Predef 中是可能的 从 other.type 到 ?{def x: ?}
的转换函数
class Point(x: Double, y: Double) {
override def toString = "(" + x + "," + y + ")"
def distance(other: Point): Double = {
sqrt((this.x - other.x)^2 + (this.y-other.y)^2 )
}
}
【问题讨论】:
标签: scala