假设:
scala> trait F {
| def foo(x: Int): Int
| }
defined trait F
我尝试创建F
的实现,但我创建了foo
的参数call-by-name
而不是call-by-value
。
scala> class FImpl extends F {
| override def foo(x: => Int): Int = 55
| }
<console>:12: error: class FImpl needs to be abstract, since method foo in trait F of type (x: Int)Int is not defined
(Note that Int does not match => Int)
class FImpl extends F {
^
<console>:13: error: method foo overrides nothing.
Note: the super classes of class FImpl contain the following, non final members named foo:
def foo(x: Int): Int
override def foo(x: => Int): Int = 55
^
编译器解释了我尝试失败的原因。
根据我的示例,是否可以定义F#foo
函数,该函数采用call-by-name
或call-by-value
参数?