1. 程式人生 > >Scala 匿名函式做參

Scala 匿名函式做參

object Demo {
  def main(args: Array[String]): Unit = {
    val funcao = (name: String) => println(s"${name},你好")
    greeting("馬總",funcao)
    greeting("李總",name=>println(s"${name} ,好"))
    greeting("朱總",println(_))
  }

  def  greeting(name:String,func:(String)=>Unit)={
        func(name)
  }
}