使用Lift with Squeryl,如何将两个类作为同一个类的子类?
我的课程如下所示:
class SubClass1 extends Record[SubClass1] with KeyedRecord[SubClass1] with CreatedUpdated[SubClass1] {
val id = ...
val field1a = StringField(...)
...
}
class SubClass2 extends Record[SubClass2] with KeyedRecord[SubClass2] with CreatedUpdated[SubClass2] {
val id = ...
val field2a = StringField(...)
}
我希望SubClass1
和SubClass2
分别是其他类的子类,比如MyParentClass。所以我认为我必须做这样的事情:
abstract class MyParentClass extends Record[MyParentClass] with KeyedRecord[MyParentClass] with CreatedUpdated[MyParentClass] {}
然后
class SubClass1 extends MyParentClass {
val id = ...
val field1a = StringField(...)
...
}
class SubClass2 extends MyParentClass {
val id = ...
val field2a = StringField(...)
...
}
这给了我错误,例如字段(StringField
)等不符合正确的类型。有关如何做到这一点的任何建议吗?
谢谢,
答案 0 :(得分:1)
抽象超类不能定义具体的类型参数,因为它需要被子类覆盖。尝试:
abstract class MyParentClass[A <: MyParentClass]
extends Record[A] with KeyedRecord[A] with CreatedUpdated[A]
然后:
class SubClass extends MyParentClass[SubClass]