scala error: class type required but T found

scala error: class type required but T found

我正在尝试创建一个通用摘要 class table 并创建一个通用 TableQuery 将其与 slick

一起使用

泛型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")
}

用法:

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]
}

这一行报错 - class type required but T found:

private def table: TableQuery[T] = TableQuery[T]

有办法解决吗?

所以我解决了这个问题。

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)
}