我是Scala的新手。请说出
之间的区别 def fun( t: Int => Int):Unit = {
和
def fun(t: =>Int):Unit {
和
def fun(t:=>Int):Unit { (without space b/w ":" and "=>"))
答案 0 :(得分:4)
def fun( t: Int => Int):Unit
是一个采用单个参数t
的方法。它的类型Int => Int
是一个带Int
的函数,并返回Int
。但是,fun
的返回类型为Unit
。
def fun(t: =>Int):Unit
是一种接受call by name参数t
的方法。同样,此方法的返回类型为Unit
。
第二种和第三种方法没有区别。