Implicit parameter resolution - setting the precedence
问题 I am trying to create a typeclass Default that supplies the default value for a given type. Here is what I have come up with so far: trait Default[A] { def value: A } object Default { def withValue[A](a: A) = new Default[A] { def value = a } def default[A : Default]: A = implicitly[Default[A]].value implicit val forBoolean = withValue(false) implicit def forNumeric[A : Numeric] = withValue(implicitly[Numeric[A]].zero) implicit val forChar = withValue(' ') implicit val forString = withValue(""