Implicit permission includes searching for a companion object for the type of the implicit parameter , and also companion objects for enter the parameters of the implicit parameter . In the example above, the card signature is as follows
def map[B, That](f: (Int) => B)(implicit bf: CanBuildFrom[Array[Int], B, That]): That
Since we have no type requirements for what we can ignore it at the moment. After we look in the local and container regions and find no matching implications, the next place to look for the implicit will be the companion object for CanBuildFrom. However, it does not have a companion object. Therefore, we continue and look into the array for implicit. Find one in the form
implicit def canBuildFrom[T](implicit m: ClassManifest[T]): CanBuildFrom[Array[_], T, Array[T]]
Since we do not have type requirements or implicit matching, "This" is forced to be of type Array [Int] and completes our typing.
Neil essy
source share