0

为什么在编译此代码段时出现错误?

trait ID[R <: Record[R] with KeyedRecord[Long]] {

  this: R =>

  val idField = new LongField(this)
}

错误:

inferred type arguments [ID[R] with R] do not conform to class LongField's
type parameter bounds [OwnerType <: net.liftweb.record.Record[OwnerType]]

我怎样才能解决这个问题?


长字段定义:

class LongField[OwnerType <: Record[OwnerType]](rec: OwnerType)
  extends Field[Long, OwnerType] with MandatoryTypedField[Long] with LongTypedField {
4

1 回答 1

1

兑换

val idField = new LongField(this)

val idField = new LongField[R](this)

如果您不指定 type R,则 LongField 无法检查该类型是否是协变的Record[OwnerType]。明确提及它应该解决目的。

PS:我不知道要重新确认的其他类声明,但以下声明有效:

case class Record[R]
class KeyedRecord[R] extends Record[R]
class LongField[OwnerType <: Record[OwnerType]](rec: OwnerType)
trait ID[R <: Record[R] with KeyedRecord[Long]] {
  this: R =>
  val idField = new LongField[R](this)
}
于 2013-05-01T08:27:36.060 回答