考虑 Scala 中的以下函数:
def wrapMyFunction[A](foo: =>A):A = {
try {
foo
}
catch { case e =>
//Return whatever the "empty" or "default" instance of type A would be,
//such as 0, "", None, List(), etc.
}
}
给定类型参数 A,如何获取类型 A 的“空”或“默认”值?甚至可能吗?