exp*_*ert 5 scala implicit-conversion implicits slick slick-3.0
有这个帖子,讨论implicits的链接,但我认为它不包括我的情况,因为我有通用implicits.演示此问题的示例项目位于此处.要重现这两条线应该被注释掉.
所以我对具体类型有许多含义,例如
implicit val ObjectIdColumnType: ColumnType[ObjectId] = MappedColumnType.base[ObjectId, Array[Byte]](
{ obj => obj.toByteArray }, { arr => new ObjectId(arr) }
)
Run Code Online (Sandbox Code Playgroud)
我希望所有这些都能自动生成GetResult[T]
隐式val.因此我写了以下功能
implicit def getResultForTypedTypes[T](implicit bct: ColumnType[T]): GetResult[T] =
GetResult[T](r => bct.getValue(r.rs, r.currentPos))
Run Code Online (Sandbox Code Playgroud)
我希望这个功能与原型如
def << [T](implicit f: GetResult[T]): T = f(this)
Run Code Online (Sandbox Code Playgroud)
能够接受 GetResult[ObjectId]
可悲的是我得到了错误
Error:(78, 20) could not find implicit value for parameter f: slick.jdbc.GetResult[org.bson.types.ObjectId]
val id = r.<<[ObjectId]
^
Run Code Online (Sandbox Code Playgroud)
我启用了log-implicits,发现看似无关的隐式隐藏在某种程度上
Information:(78, 20) getResultForTypedTypes is not a valid implicit value for slick.jdbc.GetResult[org.bson.types.ObjectId] because:
hasMatchingSymbol reported error: ambiguous implicit values:
both value strListTypeMapper in object MyAPI of type => co.greenhouse.rabbit.server.db.MyPostgresDriver.DriverJdbcType[List[String]]
and value ObjectIdColumnType in object MyAPI of type => co.greenhouse.rabbit.server.db.MyPostgresDriver.BaseColumnType[org.bson.types.ObjectId]
match expected type co.greenhouse.rabbit.server.db.MyPostgresDriver.api.BaseColumnType[T]
val id = r.<<[ObjectId]
^
Run Code Online (Sandbox Code Playgroud)
我怎样才能找到这个暗示意义上的问题?
归档时间: |
|
查看次数: |
180 次 |
最近记录: |