相关疑难解决方法(0)

在Scala中定义函数的这三种方式之间的差异

给出了表达相同功能的三种方式f(a) := a + 1:

val f1 = (a:Int) => a + 1
def f2 = (a:Int) => a + 1
def f3:(Int => Int) = a => a + 1
Run Code Online (Sandbox Code Playgroud)

这些定义有何不同?REPL没有表明任何明显的差异:

scala> f1
res38: (Int) => Int = <function1>
scala> f2
res39: (Int) => Int = <function1>
scala> f3
res40: (Int) => Int = <function1>
Run Code Online (Sandbox Code Playgroud)

scala

92
推荐指数
2
解决办法
2万
查看次数

标签 统计

scala ×1