【发布时间】:2016-04-02 07:59:11
【问题描述】:
我有一个编译错误,我不明白。
case class Point(x: Int, y: Int)
trait Rectangular {
def topLeft: Point
def bottomRight: Point
def left = topLeft().x //Compile error occurring here
def right = bottomRight.x
def width = right - left
// any many more concrete geometric methods.
}
我在定义第三个方法的那一行出现编译错误,提示“Point does not take parameters”。
但我认为你可以调用一个不带参数的函数,不管有没有()。因为topLeft只是一个没有参数的方法,返回类型为Point。
【问题讨论】:
标签: scala function methods traits