0
創建從方法調用不帶參數的函數需要以下語法: -轉換方法調用與函數的參數不帶參數
VAL d =顯示_
如何使用參數進行方法調用時也是這樣。 請找到下面的示例代碼。
package paf
/**
* Created by mogli on 8/27/17.
*/
object PafSample {
def display(): Unit ={
println("display is a no argument method")
}
def evenOdd(input : Int) : Unit = if(input % 2 == 0) println(s"$input is even") else println(s"$input is odd")
def main(args: Array[String]): Unit = {
//This is working
val d = display _
executeFunction(d)
//TODO : convert to a function call that takes no arguments,
// so that, it can be passed to executeFunction as parameter
//val e = evenOdd(3) _
//executeFunction(e)
}
def executeFunction[B](f :() => B) : B = {
println("executing function")
f()
}
}
VAL d =顯示_; executeSingleArgFunction(())(d)給CTE。 – mogli
什麼是CTE?... – pedrofurla