Ich definiere implicits in Companion-Objekten, die für alle Typen außer AnyVals wie Long und Double etc. aufgelöst werden. Ich bin mir nicht ganz sicher, warum das der Fall ist? Gibt es unterschiedliche Auflösungsregeln für AnyVals?Scala implizite Auflösung für AnyVal anders?
class X(val i:Int) {
def add[T](implicit x:SomeType[T])=println(x)
}
object X {
implicit def xx = XType
implicit def ll = LType
implicit def dd = DType
}
object Console {
def main(args: Array[String]): Unit = {
new X(3).add[X] // works fine
new X(3).add[Long] // error Error:(16, 16) could not find implicit value for parameter x: com.x.SomeType[Long]
new X(3).add[Double] // error Error:(16, 16) could not find implicit value for parameter x: com.x.SomeType[Double]
}
}
sealed trait SomeType[T]
case object XType extends SomeType[X]
case object LType extends SomeType[Long]
case object DType extends SomeType[Double]