0
点赞
收藏
分享

微信扫一扫

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



 

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 条评论