如何使这个断言通过

时间:2014-04-07 19:05:00

标签: scala

我很困惑如何做到这一点。我需要将它转换为String。我试过x.toString,但它看不起作用。

def doSomething(x: Int, function: Int => String): String = ???

assert(doSomething(5, (i: Int) => i.toString) == "5")
assert(doSomething(7, (i: Int) => (i + 5).toString) == "12")

2 个答案:

答案 0 :(得分:0)

您需要实际调用或应用函数...,如:

def doSomething(x: Int, function: Int => String): String = function(x)

答案 1 :(得分:0)

尝试def doSomething(x: Int, function: Int => String): String = function(x)???只是Scala中的占位符。