Scala学习笔记(函数式编程)

mac2022-06-30  22

函数式变成介绍

函数具体代码介绍

object Test02 { def main(args: Array[String]): Unit = { val dog = new Dog println(dog.sum(10,20)) //方法转函数 val f1 = dog.sum _ println("f1=" + f1(15,20)) //函数 val f2 = (n1 : Int , n2 : Int) => { n1 + n2 } println("f2=" + f2(10,50)) } } class Dog { //方法 def sum(n1:Int , n2:Int) :Int = { n1 + n2 } }

函数的定义

函数递归调用

函数注意事项

小练习题

多行函数

最新回复(0)