【发布时间】:2011-11-04 20:36:56
【问题描述】:
Scala 2.8.1
采用以下类层次结构
abstract class A
class B extends A
class C extends A
为什么scala编译器在下面发送B的实例时找不到send的隐式参数
implicit def routingKeyFor[T <: A](value: T) =
value.getClass.getSimpleName
implicit def routingKeyFor(value: C) = "custom C"
def send[T <: A](value: T)(implicit createRoutingKey: T => String):
Validation[Throwable, String] = Success(createRoutingKey(value))
val resultOfSendingB = send(new B)
val resultOfSendingC = send(new C)
为什么当routingKeyFor的泛型版本被重命名时,编译器能够找到隐式参数的值?
implicit def someOtherName[T <: A](value: T) =
value.getClass.getSimpleName
【问题讨论】:
标签: scala implicit-conversion implicits