scala-関数デジタル面量、閉包、3種類の関数パラメータ形式
1317 ワード
def m = (x: Int) => x + 1
println(m(1))
// 1
// : ,
// more , makeInt
def makeInt(more: Int) = (x: Int) => x + more
// : more
val inc1 = makeInt(1)
println(inc1(10))
// 2:
// more,
var more = 1
// makeInt
def makeInt = (x:Int) => x + more
println(makeInt(2)) // 3
more = 4
println(makeInt(2)) // 6
// 3:
var more = 1;
val testList = List(2,3,4)
// foreach more,
testList.foreach(more += _)
println(more)
と呼ばれます.def echo(args:String*)={
for(arg
def echo(arg:String, time:String)={
println(arg)
}
echo(time="10", arg="arg")
//
// arg
def echo(arg:String, time:String, zero:Int = 0)={
println(arg)
}