在推特斯卡拉学校"基础知识持续" http://twitter.github.io/scala_school/basics2.html有以下对象定义
object addOne extends Function1[Int, Int] {
def apply(m: Int): Int = m + 1
}
Run Code Online (Sandbox Code Playgroud)
我不完全理解[Int,Int]类型参数化.当我们扩展Function1时,我相信我声明我将有一个带有单个参数的apply,为什么我的apply被构建为只接受一个Int参数时,Function1 [Int,Int]中的第二个Int?
请解释.
Inf*_*ity 11
它是返回类型.Function1[Int, Int]是一样的Int => Int.需要一个Int并返回一个Int.
我们可以scala.Function1像这样写简化:
trait Function1[T1, R]{
def apply(v1: T1): R
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1489 次 |
| 最近记录: |