原来scala函数参数定义=>左边可以不加参数,表示无参,并且可以用大括号代替小括号

来源:互联网 发布:淘宝红包使用规则 编辑:程序博客网 时间:2024/05/01 21:38
object WithScope {  def withScope2(fun: =>String)={    fun  }    def fun()={    println("haha")    "success"  }  def main(args: Array[String]): Unit = {    withScope2(fun)  }}

object WithScope {  def withScope2(fun: =>String)={    fun  }  def withScope1(fun: (String)=>String)={    fun  }  def fun()={    println("haha")    "success"  }  def main(args: Array[String]): Unit = {    withScope2{fun;println(11);"111"}  }}

0 0
原创粉丝点击