斯卡拉 2.8.1
采用以下类层次结构
abstract class A
class B extends A
class C extends A
send
为什么scala编译器在发送B
下面的实例时找不到隐式参数
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