scala 接收函数作为参数及返回函数
object FunctionDemo {
/**
* 定义函数
* 参数类型为函数
* 返回类型为函数
*/
def func(name1: String, name2: String, f: (Int, Int) => String): (String, Int) => Int = {
val temp = f(1, 2)
(a: String, b: Int) => {
a.size + b + temp.size
}
}
val value = func("name1", "name2", (a: Int, b: Int) => {
(a + b).toString()
})("aaa", 10)
println(value)
def main(args: Array[String]): Unit = {
}
}
网友评论