这个隐式val如何导致StackOverFlowError?
(削减我的原始代码,仍然导致错误)
object Complicit {
// a class with name, default, and conversion function as implicit val
case class CC[A](name: String, defaultValue: A)(implicit val convert: String => A) {
def getFrom(s: String): A= try {
convert(s)
} catch {
case t: Throwable =>
println("ERROR: %s".format(t)) // just to see the StackOverflowException
defaultValue
}
}
// this works fine
object Works {
val cc1= CC("first", 0.1)(_.toDouble)
}
// this causes java.lang.StackOverflowError due to the implicit
object Fails {
// !!! StackOverFlowError …Run Code Online (Sandbox Code Playgroud)