一 代码块
{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)Stringhello("cakin24")//> res0: String = Hello,cakin24def hello2(name:String)={s"Hello,${name}"}//> hello2: (name: String)Stringhello("cakin24")//> res1: String = Hello,cakin24def Add(x:Int,y:Int)=x+y //> Add: (x: Int, y: Int)IntAdd(1,2)//> res2: Int = 3}

1941

被折叠的 条评论
为什么被折叠?



