object Test extends App {
def print(s: String)(implicit p: Prefixer) = {
println(p.prefix + s)
}
print("test")
}
case class Prefixer(prefix: String)
object Prefixer {
implicit val p = Prefixer("***")
}
上述代碼無法編譯,因爲編譯器無法爲Prefixer找到隱式值。但是,如果我將案例類Prefixer和伴隨對象放在另一個文件中,它就可以工作。這是爲什麼?伴隨對象的斯卡拉隱式邏輯
重複的http://stackoverflow.com/questions/25468583/why-cant-scala-find-my-typeclass-instance-defined-implicitly-in-the-companion-o – 2014-08-31 11:46:10