我是 Scala 的新手。请说出两者的区别
def fun( t: Int => Int):Unit = {
和
def fun(t: =>Int):Unit {
和
def fun(t:=>Int):Unit { (without space b/w ":" and "=>"))
我是 Scala 的新手。请说出两者的区别
def fun( t: Int => Int):Unit = {
和
def fun(t: =>Int):Unit {
和
def fun(t:=>Int):Unit { (without space b/w ":" and "=>"))
def fun( t: Int => Int):Unit
是一种采用单个参数的方法,t
. 它的类型 ,是一个接受, 并返回 的Int => Int
函数。但是,返回类型是.Int
Int
fun
Unit
def fun(t: =>Int):Unit
是一种通过名称参数接受调用的方法t
。同样,此方法的返回类型是Unit
.
请参阅什么是“按名称呼叫”?也。
第二种和第三种方法没有区别。