我写了这个光滑的代码,它按预期工作
object TestApp extends App {
implicit val getFooResult = GetResult(r => Foo(r.<<, r.<<))
val query = sql"select a, b from foo".as[Foo]
}
case class Foo(a: Long, b: String)
这编译并运行正常。但如果我将代码更改为
object TestApp extends App with MyImplicits {
val query = sql"select a, b from foo".as[Foo]
}
trait MyImplicits {
implicit val getFooResult = GetResult(r => Foo(r.<<, r.<<))
}
case class Foo(a: Long, b: String)
现在我收到编译错误
could not find implicit value for parameter rconv: slick.jdbc.GetResult[Foo]
当我尝试
时会发生同样的事情object TestApp extends App {
import MyImplicits.getFooResult
val query = sql"select a, b from foo".as[Foo]
}
object MyImplicits {
implicit val getFooResult = GetResult(r => Foo(r.<<, r.<<))
}
case class Foo(a: Long, b: String)
它仍然提供相同的错误,并且没有看到隐含在对象中定义。
当我在特征或对象中移动它时,为什么我会忽略隐含的可见性?