我有以下记录和 DAO:
abstract class SuperRecord
class Record1 extends SuperRecord
class Record2 extends SuperRecord
abstract class SubRecord extends SuperRecord
class SubRecord1 extends SubRecord
abstract class DAO[T <: SuperRecord] extends scala.slick.driver.MySQLDriver.simple.Table[T]
object DAO1 extends DAO[Record1]
object DAO2 extends DAO[Record2]
abstract class SubDAO extends DAO[T <: SubRecord]
object SubDAO1 extends SubDAO[SubRecord1]
那么SuperRecord和Record有以下方法
abstract class SuperRecord {
def table: DAO[T] forSome {type T <: SuperRecord}
}
class Record1 extends SuperRecord {
def table = DAO1
}
所有这些都满足类型检查器。但是,我想更改 SuperRecord 中“def table”的签名以指示 T是记录类型,即在Record1中,表的类型是 DAO[Record1] 而不是 DAO[T :< SuperRecord],类似于
def table: DAO[this.type]
或者
def table: T forSome {type T <: DAO[U forSome {type U <: this.type }]}
两者都不满足类型系统。我试图在 Scala 中完成的工作是否可行,如果可以,我应该使用什么“表”签名?