潜心_守道
2019-10-31 14:57
def greeting() = {name: String} => { s"Hello $name"}
//> greeting: ()String => String
greeting()("zhangsan") //> res1: String = Hello zhangsan
def greetings() = (name: String) => ("Hello"+" "+name)
//> greetings: ()String => String
greetings()("zhangsan") //> res2: String = Hello zhangsan
def greet() = (name: String) => {"Hello"+" "+name}
//> greet: ()String => String
greet(){"zhangsan"} //> res3: String = Hello zhangsan
def greets(age: Int) = {name: String} => {"Hello"+" "+name+age}
//> greets: (age: Int)String => String
greets(23){"zhangsan"} //> res4: String = Hello zhangsan23
经过测试,非匿名函数的参数列表不能用大括号,匿名函数的参数和函数体大括号小括号通用
Scala程序设计—基础篇
37007 学习 · 77 问题
相似问题