[英]scala error: class type required but T found
I'm trying to create a generic abstract class table and create a generic TableQuery
using it with slick
我试图创建一个通用的抽象类表,并创建一个通用的
TableQuery
使用它与slick
The generic Table: 通用表:
trait TaskRow {
def dvProjectId: Int
def timestamp: Long
def status: String
}
abstract class TaskTable[T](tag: Tag, name: String) extends Table[T](tag, name) {
def id: Rep[Int] = column[Int]("Id")
def status: Rep[String] = column[String]("Status")
}
Usage: 用法:
case class ATaskRow(id: Int, status: String) extends TaskRow
class ATaskTable(tag: Tag) extends TaskTable[ATaskRow](tag, "A") {
def * : ProvenShape[ATaskRow] = (id, status) <> (ATaskRow.tupled, ATaskRow.unapply)
}
class Repo[T <: TaskTable[R], R <: TaskRow] @Inject()(db: DB) {
...
private def table: TableQuery[T] = TableQuery[T]
}
this line gives an error - class type required but T found
: 这行给出了一个错误-
class type required but T found
:
private def table: TableQuery[T] = TableQuery[T]
There's a way I can fix it? 有办法解决吗?
So I solved this. 所以我解决了这个问题。
class ARepo @Inject()(db: DB)
extends Repo[ATaskTable, ATaskRow](db, (tag: Tag) => new ATaskTable(tag))
class Repo[T <: TaskTable[R], R <: TaskRow] (db: DB, cons: Tag => T) {
...
private def table: TableQuery[T] = TableQuery(cons)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.