[英]Unspecified value parameter rconv
I had these lines in my code 我的代码中有这些行
val x = database.withSession { implicit session =>
StaticQuery.queryNA[Long](s"select id from .....")
}
val y = database.withSession { implicit session =>
StaticQuery.queryNA[Long](s"select id1 from .....")
}
val z = database.withSession { implicit session =>
StaticQuery.queryNA[(Long, Long)](s"select id1, id2 from .....")
}
In order to minimize code duplication I changed my code to 为了减少代码重复,我将代码更改为
def genericExec[T](query: String) : List[T] = {
database.withSession { implicit session =>
StaticQuery.queryNA[T](query).list
}
}
for {
x <- genericExec[Long](query1)
y <- genericExec[Long](query2)
z <- genericExec[(Long, Long)](query3)
} {...}
Of course I get an error now that 当然我现在得到一个错误
Error:(16, 32) not enough arguments for method queryNA: (implicit rconv: scala.slick.jdbc.GetResult[T])scala.slick.jdbc.StaticQuery[Unit,T].
Unspecified value parameter rconv.
StaticQuery.queryNA[T](query).list
Since the type T is totally generic its impossible for me to provide all types of conversions. 由于类型T是完全通用的,因此我无法提供所有类型的转换。 So how can I keep my generic implementation and just provide the conversions which my type T is actually using in my code (aka Long, and (Long, Long)
因此,如何保留我的通用实现,而只提供我的类型T实际上在我的代码中使用的转换(又名Long和Long,Long)
Because queryNA
has a GetResult
constraint on T
, your function has to have the same constraint. 由于
queryNA
在T
上具有GetResult
约束,因此您的函数必须具有相同的约束。 You need to tell your generic method that it is only valid for types T
that have a GetResult
defined, so: 您需要告诉您的通用方法,该方法仅对定义了
GetResult
T
类型有效,因此:
def genericExec[T : GetResult](query: String) : List[T] = ...
or equivalently: 或等效地:
def genericExec[T](query: String)(implicit rconv: GetResult[T]) : List[T] = ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.