2

我是 Scala 的新手。请说出两者的区别

    def fun( t: Int => Int):Unit = {

    def fun(t: =>Int):Unit {

    def fun(t:=>Int):Unit { (without space b/w ":" and "=>"))
4

1 回答 1

4

def fun( t: Int => Int):Unit是一种采用单个参数的方法,t. 它的类型 ,是一个接受, 并返回 的Int => Int函数。但是,返回类型是.IntIntfunUnit

def fun(t: =>Int):Unit是一种通过名称参数接受调用的方法t。同样,此方法的返回类型是Unit.

请参阅什么是“按名称呼叫”?也。

第二种和第三种方法没有区别。

于 2016-10-19T14:39:35.683 回答