1. 程式人生 > >scala 函式定義方法們

scala 函式定義方法們

object test extends App{

val fun1=(x:Int,y:Int)=>x+y

val fun2=((x:Int,y:Int)=>x+y)

val fun3=(_:Int)+(_:Int)

val fun4:(Int,Int)=>Int=(_+_)

val fun5:(Int,Int)=>Int=(x,y)=>x+y

val fun6=new Function2[Int,Int,Int]{
override def apply(x: Int, y: Int): Int = if(x<y) x else y
}

val fun7=(x:Int,y:Int)=>if(x<y) x else y

//無參函式,小括號不能省
val fun8=()=>println("haha")
fun8()
}