我是斯卡拉的新手。我不明白以下代码的编译错误:
def delayed( t:(Int)=> Int):Unit={
println("In delayed method")
var y=t;
println(y)
}
def time(x:Int):Int={
x*2
}
当我打电话时
delayed(time(8))
我收到以下错误:
scala> delayed(time(8))
<console>:15: error: type mismatch;
found : Int
required: Int => Int
delayed(time(8))
^
请解释一下是什么问题?还请建议一个很好的链接来理解 scala 中的函数和函数文字。我无法完全理解。
非常感谢
编辑:
请说出两者的区别
def delayed( t: Int => Int):Unit = {
和
def delayed(t: =>Int):Unit {
和
def delayed(t:=>Int):Unit { (without space b/w ":" and "=>"))