【发布时间】:2015-02-27 15:39:05
【问题描述】:
谁能解释一下为什么在我的 trait 中声明 TableQuery 时出现以下编译器异常。
class type required but T found
T 实际上不是 Class 类型还是我弄错了?
trait TableModel[T <: Table[_]] {
val table: TableQuery[T] = TableQuery[T] <~~~~~~~~~~ class type required but T found
def exists(implicit session: Session): Boolean =
(!MTable.getTables(table.baseTableRow.tableName).list.isEmpty)
def schemaDescription: MySQLDriver.SchemaDescription = table.ddl
def create(implicit session: Session): Unit = schemaDescription.create
def drop(implicit session: Session): Unit = schemaDescription.drop
}
object UsersTable extends TableModel[Users] {}
【问题讨论】:
-
你在哪一行得到这个错误?这通常发生在您尝试创建泛型参数的实例时,例如stackoverflow.com/questions/20591957/….
-
val table: TableQuery[T] = TableQuery[T] 异常在下面一行
-
您回答的问题与我的问题不完全相同。虽然您发布的问题试图创建 T 的实例,但我要做的就是在 slick 提供的另一个泛型类中重用泛型。
-
T是类型参数,不是类类型。