The book "Programming in Scala" specifies:
Up through Scala 2.7, that was the end of the story. Whenever multiple implicit conversions applied, the compiler refused to choose between them. ... Scala 2.8 loosens this rule. If one of the available conversions is strictly more specific than the others, then the compiler will choose the more specific one. ... one implicit conversion is more specific than another if one of the following applies:
• The argument type of the former is a subtype of the latter’s.
Consider the following case:
object Encoder {
implicit def fromInt(x: => Int) = { println("int"); new Encoder }
implicit def fromIntArray(x: => Array[Int]) = { println("int array"); new Encoder }
implicit def fromGenericArray[T](x: => Array[T])(implicit subencoder: (=> T) => Encoder) = {
println("generic array")
subencoder(x(0))
new Encoder
}
}
val e: Encoder = Array(1)
Multiple conversions can apply here, but it seems that fromIntArray is picked up. When fromIntArray is not present, fromGenericArray is chosen. My question is, is this specific case where the rule above applies so that can I safely expect that fromIntArray would apply for Array[Int] and fromGenericArray for all other Array[T]'s?