一 代码块
{exp1;exp2}
{
exp1
exp2
}
代码块也是一个表达式,其最终的求值是最后一个表达式的值。
二 函数
def functionName(param:ParamType):ReturnType={
//function body:expressions
}
三 实例
object func_examples {
def hello(name:String):String={
s"Hello,${name}"
}//> hello: (name: String)String
hello("cakin24")//> res0: String = Hello,cakin24
def hello2(name:String)={
s"Hello,${name}"
}//> hello2: (name: String)String
hello("cakin24")//> res1: String = Hello,cakin24
def Add(x:Int,y:Int)=x+y //> Add: (x: Int, y: Int)Int
Add(1,2)//> res2: Int = 3
}