给定三个属于一起的类(我试图通过类型参数来表达这一点):
abstract class Row[T <: Table[T, R, B],
R <: Row[T, R, B],
B <: RowBuffer[T, R, B]] extends Immutable {
def id: Int
def getTable: T
def toRowBuffer: B
def delete() {
// does not compile: Found Row.this.type ... Row[T, R, B], required: R
getTable.delete(this)
}
}
abstract class RowBuffer[T <: Table[T, R, B],
R <: Row[T, R, B],
B <: RowBuffer[T, R, B]] extends Mutable {
def id: Int
def getTable: T
def toRow: R
def insert(): R = {
// does not compile: Found RowBuffer.this.type ... RowBuffer[T, R, B],
// required: B
getTable.insert(this)
}
}
abstract class Table[T <: Table[T, R, B],
R <: Row[T, R, B],
B <: RowBuffer[T, R, B]] {
def insert(b: B): R = {
// insert ...
b.toRow
}
def delete(r: R) {
// delete ...
}
如果有“跨类”调用,我还没有设法定义正确的类型。所以我的问题是:
- 这个问题叫什么名字?
- 如何以类型安全的方式表达它?