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

阅读 131

2022-07-28



 

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 0 举报